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

rake, ruby, ruby-on-rails

Solution

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

Problem

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?

Original source