Set Multiple Environmental Variables On Invocation of Rake Task
Asked Answered
A

1

6

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?

Anticlerical answered 4/2, 2014 at 22:14 Comment(2)
ONE=1 TWO=2 ruby -e 'puts ENV["ONE"]; puts ENV["TWO"]' works for me (also with rake), in bash and in zsh (gnome-term).Neuromuscular
What does temp:both do?Ungula
A
4

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
Anchoveta answered 4/2, 2014 at 22:28 Comment(1)
One of the envs I was passing in was RAILS_ENV. This was switching the environment and making a Rake task included in a Gem that was in the development group unavailable, causing error.Anticlerical

© 2022 - 2024 — McMap. All rights reserved.