24

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

Karim Mtl
  • 1,223
  • 3
  • 11
  • 39

2 Answers2

58

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]")
Rajarshi Das
  • 11,778
  • 6
  • 46
  • 74
  • 4
    Note you have to call `.reenable` to run the same task twice. See http://stackoverflow.com/questions/22639194/invoking-the-same-rake-task-twice-in-rspec – max pleaner Mar 03 '17 at 23:17
8

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
ChrisBarthol
  • 4,871
  • 2
  • 21
  • 24