Setting multiple environment variables when invoking a Rake task

I can call the Rake task and set one environment variable as follows:

$ ONE=1 rake temp:both

But how to set two environment variables?

This does not work:

 $ ONE=1 TWO=2 rake temp:both 

This works, but is confusing:

$ ONE=1 rake temp:both TWO=2 

How to pass more than one env before a call rake?

+4
source share
1 answer

I agree with @Ernest; he should work. Here's a sample ...

Rake task for echo booths:

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

Task completion:

VAR1=first VAR2=second bundle exec rake echo_env

Output:

VAR1: first
VAR2: second
+3
source

Source: https://habr.com/ru/post/1525325/


All Articles