Here is an tutorial how to pass parameters to an capistrano 3 task.
namespace :task do
desc 'Execute the specific cmd task'
task :invoke, :command do |task, args|
on roles(:app) do
execute :cmd, args[:command]
end
end
end
Can executed with:
$ cap staging "task:invoke[arg]"
How can i use this in my deploy.rb? The following does not work.
before :started, "task:invoke[arg]"
How does Capistrano work? Capistrano is a framework written in Ruby that provides automated deploy scripts. It connects to your web server via SSH and executes a bunch of tasks that will make your app ready to shine.
Navigate to your application's root directory in Terminal and run the following command: capify . This command creates a special file called Capfile in your project, and adds a template deployment recipe at config/deploy.
Not sure about before/after
, but with Capistrano 3
you can always use the rake
syntax and call task from within another task:
Rake::Task["mynamespace:mytask"].invoke(arg)
You can use invoke
method:
before :started, :second_param do
invoke 'task:invoke', 'arg'
end
Also one thing which might be helpful, capistrano and rake allowing to execute task only first time, this might be common issue for task with parameters, cause you may reuse it with different value. To allow doing it you need to re-enable the task:
namespace :task do
desc 'Execute the specific cmd task'
task :invoke, :command do |task, args|
on roles(:app) do
execute :cmd, args[:command]
task.reenable # <--------- this how to re-enable it
end
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With