CruiseControl and custom cruise tasks running in production

September 20, 2007

I found a fun gotcha! today with CruiseControl - if you create a custom cruise task you have to set the RAILS_ENV AND ENV["RAILS_ENV"] to test.

If you do not, CruiseControl will run against your production database. Before CruiseControl invokes it's own built-in cruise task it sets the RAILS_ENV to "test", but several lines before that is where it checks for and runs your cruise task, if you define it.

I'm not sure why they don't set the environment before this, but they don't - so be careful!

This is from the CruiseControl manual:

WARNING: with Rails projects, it is important that RAILS_ENV does not default to ‘production’. Unless you want your migration scripts and unit tests to hit your production database, of course. CruiseControl.reb leaves this variable unchanged when invoking ‘cruise’ or other custom Rake task, and sets it to ‘test’ before invoking the defaults.

Fortunately the fix is easy, just make sure you set RAILS_ENV = ENV['RAILS_ENV'] = 'test' in your task.

Add comment

About

I'm a programmer and shutterbug living on the West Coast of Canada.

Blog Archive

Recently Heard

A Liberal Educationby New Model ArmyPlayed on 2008/07/16 at 02:35PM
The Two Sides of Monsieur Valentineby SpoonPlayed on 2008/07/16 at 02:32PM
You Weren't Thereby New Model ArmyPlayed on 2008/07/16 at 02:28PM
Powered by Viviti