简体   繁体   中英

How do I pass environmental variables to a Rake task invoked from another Rake task?

I have three Rake tasks invoked from another Rake task. The first Rake task requires that an environmental variable is set before it is executed.

The following works, however it means that I lose all the output from the task which is critical:

namespace :deploy do

  task :staging => :environment do
    `EXAMPLE=something rake db:rebuild`
    Rake::Task["rake envs:push:staging"].invoke
    Rake::Task["rake app:push:staging"].invoke
  end

end

How can I invoke the first task with the environmental variable AND display its output to the terminal?

ENV['EXAMPLE'] = 'something'
Rake::Task['db:rebuild'].invoke

使用system代替后退:

system("EXAMPLE=something rake db:rebuild")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM