Update: For Capistrano 3, see scieslak’s answer.
As jarrad has said, capistrano-ash
is a good basic set of helper modules to deploy other project types, though it’s not required as at the end of the day it’s just a scripting language and most tasks are done with the system commands and end up becoming almost shell script like.
To pass in parameters, you can set the -s flag when running cap to give you a key value pair. First create a task like this:
desc "Parameter Testing"
task :parameter do
puts "Parameter test #{branch} #{tag}"
end
Then start your task like so:
cap test:parameter -s branch=master -s tag=1.0.0
For the last part, I would recommend setting up passwordless access using ssh keys to your server, but if you want to take it from the current logged in user, you can do something like this:
desc "Parameter Testing"
task :parameter do
system("whoami", user)
puts "Parameter test #{user} #{branch} #{tag}"
end
UPDATE: Edited to work with the latest versions of Capistrano. The configuration array is no longer available.
Global Parameters: See comments Use set :branch, fetch(:branch, 'a-default-value')
to use parameters globally. (And pass them with -S instead.)