Passing parameters from one task to another within Capistrano

937 views
Skip to first unread message

Justin Diana

unread,
Feb 1, 2010, 11:06:11 PM2/1/10
to capis...@googlegroups.com
Hey all,

I've got a task that can be run from the command line with a task_to_run parameter specified:

cap admin_server rake_tasks:run_rake_on_app -s task_to_run="db:migrate"

That will execute:

 task :run_on_app, :roles => :app do
    run <<-CMD
    cd #{current_path} &&
    rake #{task_to_run} RAILS_ENV=#{rails_env}
    CMD
  end

That runs just fine.

However, I have another task (within my deploy.rb file) that I would also like to run this task.  How do I format the command so that it essentially passes the equivalent of the "-s task_to_run=" to it?

I tried:

task :clear_sessions, { :roles => :app, :only => { :primary => true }} do
    rake_tasks.run_on_primary_app task_to_run="db:sessions:clear"
end

and 

task :clear_sessions, { :roles => :app, :only => { :primary => true }} do
    task_to_run = "db:sessions:clear"
    rake_tasks.run_on_primary_app(task_to_run)
end

What am I doing wrong?

jmadtech

unread,
Feb 1, 2010, 11:09:12 PM2/1/10
to Capistrano
Nevermind... sorry to have bothered. The following worked.

task :clear_sessions, { :roles => :app, :only => { :primary => true }}
do

set :task_to_run, "db:sessions:clear"
rake_tasks.run_on_primary_app
end

Reply all
Reply to author
Forward
0 new messages