如何将环境变量传递给从另一个Rake任务调用的Rake任务?

时间:2021-04-28 22:49:37

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.

我从另一个Rake任务调用了三个Rake任务。第一个Rake任务要求在执行环境变量之前设置它。

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?

如何使用环境变量调用第一个任务并将其输出显示到终端?

2 个解决方案

#1


15  

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

#2


2  

Use system instead of back-ticks:

使用系统代替后退:

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

#1


15  

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

#2


2  

Use system instead of back-ticks:

使用系统代替后退:

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