Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Multiple Environmental Variables On Invocation of Rake Task

I can invoke a Rake task and set a single environmental variable like this:

$ ONE=1 rake temp:both

But how do I set two environmental variables?

This doesn't work:

 $ ONE=1 TWO=2 rake temp:both 

This works, but is confusing to read:

$ ONE=1 rake temp:both TWO=2 

How can I pass more than one env before the call to rake?

like image 778
Undistraction Avatar asked Feb 04 '14 22:02

Undistraction


People also ask

How do you call a rake task?

Go to Websites & Domains and click Ruby. After gems installation you can try to run a Rake task by clicking Run rake task. In the opened dialog, you can provide some parameters and click OK - this will be equivalent to running the rake utility with the specified parameters in the command line.


1 Answers

Agree with @Ernest; it should work. Here's a sample...

Sample rake task to echo vars:

task :echo_env do
  puts "VAR1: #{ENV['VAR1']}"
  puts "VAR2: #{ENV['VAR2']}"
end

Execute task:

VAR1=first VAR2=second bundle exec rake echo_env

Output:

VAR1: first
VAR2: second
like image 127
steakchaser Avatar answered Oct 27 '22 19:10

steakchaser