I'm in the process of upgrading from Capistrano 2 to Capistrano 3. In Cap 2 I was using the following to take a command line argument as the branch name (otherwise default to master
)
set :branch, fetch(:branch, "master")
If I called cap deploy
it would deploy the master branch. But it also let me do something like this:
cap deploy -S branch=foo
Which would deploy the foo
branch.
Now, in Capistrano 3, if I try to run the above I get an error: invalid option: -S
.
What's the proper way to pass an argument via the command line now?
Rake tasks (which cap is using) are supporting arguments.
cap -T outputs:
Example of invocation:
Also, here is a helpful post
P.S.: you should use env vars for "global" settings. Like common values for multiple tasks.
What I ended up doing was setting an
ENV
variable.So now I can call
And it will deploy
mybranch
. If I run a simplecap production deploy
it will deploy the default branch (master
if you don't set one, but I've changed mine below todefault
to demonstrate)This is the code I put in my
deploy.rb
file:To give an updated and working solution for Capistrano 3 (as it took me a while to find and too many tests to make it works).
My files are like:
In
staging.rb
I have:(In
server 'staging'
,staging
is a SSH connexion, defined in my.ssh/config
)Then, to deploy a specific revision, I just need to call:
Where
3b2d9ab
is the Git commit hash (short or long version).