I’m using capistrano for deployment. I’m trying to define a task which will:
cd other-rails-app && bundle exec rake sometask
But it’s complaining about Rake not being part of the bundle (which is obviously not true in the project where I am trying to run this task). I think it must be altering the environment somehow before executing the command and assuming bundler is already loaded (which is true in the capistrano task, but it’s the wrong Gemfile).
How do I run a command locally with capistrano with a clean environment?
I figured out the problem. When you run capistrano, the
BUNDLE_GEMFILEenvironment variable gets set to the Gemfile of the current project. So when you runbundle exec rake, Bundler looks first to the Gemfile set in the environment. The solution is to “reset” this Gemfile variable. I created a script for running my rake task in the root of my other project.So instead of doing:
I do this:
In the
mytask.rbfile I do this: