25

I would like to be able to pass arguments for a task that I have to call from another task

Invoking without arguments works for me like this:

Rake::Task["mytask1"].invoke 

However with arguments like this it does not:

Rake::Task["mytask1[1,v18_0,20141230]"].invoke 

Thanks

2 Answers 2

60

you can try

Rake::Task[:my_task].invoke(1,'v18_0',20141230) 

or you can do

Rake.application.invoke_task("my_task[1, 'v18_0', 20141230]") 
Sign up to request clarification or add additional context in comments.

1 Comment

Note you have to call .reenable to run the same task twice. See stackoverflow.com/questions/22639194/…
9

You can pass in parameters through invoke

namespace :tester do desc "test" task :test, [:amount] => :environment do |task, args| puts "Your amount is #{args.amount}" end task :test_task do Rake::Task["tester:test"].invoke(100) end end rake tester:test_task Your amount is 100 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.