Continuous Integration and CruiseControl.rb

by Charles Max Wood on October 20, 2009

At work, we recently got all of our spec passing and determined that we needed to stay on top of keeping the test suite updated so that we knew that the quality of our product wasn’t compromised. To solve this, we implemented continuous integration with CruiseControl.rb.

Continuous Integration

The idea is to provide regular checks on the quality of your code. In our case, this means running the RSpec tests we’ve written for our Ruby on Rails application. Each time we commit to our git repository, CruiseControl connects to the repository and pulls down the latest code. It then runs all of our tests to let us know if anything has been broken in the latest commits. It provides a visible check to the entire team letting us know if someone committed broken code.

CruiseControl.rb

CruiseControl is just one of many continuous integration systems available. You can download it here and unpack it wherever its convenient. Once you have it installed, go to the root folder for CruiseControl and add your application.

cd /path/to/cruisecontrol
./cruise add your_project --source-control git --repository git@github.com:/your_user/your_project

I did have a few issues getting it going. The main thing I did was add the cruise_control.rb file to my project:

# Project-specific configuration for CruiseControl.rb

Project.configure do |project|

  # Send email notifications about broken and fixed builds to email1@your.site, email2@your.site (default: send to nobody)
   project.email_notifier.emails = ['test@pmamediagroup.com']

  # Set email 'from' field to john@doe.com:
  # project.email_notifier.from = 'john@doe.com'

  # Build the project by invoking rake task 'custom'
  # project.rake_task = 'custom'

  # Specify the branch you're testing
  # This needs to be set if you used the -b option to cruse add
  # project.source_control.branch = 'release'

  # Build the project by invoking shell script "build_my_app.sh". Keep in mind that when the script is invoked,
  # current working directory is [cruise data]/projects/your_project/work, so if you do not keep build_my_app.sh
  # in version control, it should be '../build_my_app.sh' instead
  project.build_command = './build_script.sh'

  # Ping Subversion for new revisions every 5 minutes (default: 30 seconds)
  # project.scheduler.polling_interval = 5.minutes
  # project.rake_task = 'spec'
  project.scheduler.polling_interval = 1.hours

end

I never could get the emails to send. I was trying to send them through Gmail.

The real trick in this instance was to get all of the tests to run. I finally moved everything into a shell script so that CruiseControl would run my migrations, install my gems, and then run my tests. Here’s the script, it’s pretty simple.

#!/bin/bash

rake gems:install
rake db:migrate
rake db:test:clone
rake spec
rake metrics:all

Now I keep the page up and get notified is someone broke the build.

  • http://wwww.twitter.com/raghuonrails Raghu

    Nice article …! ..But does cruise control scale with ruby 1.8.7 ?? ..If yes, then let me know how? …

    • http://charlesmaxwood.com Chuck

      I’m using cruisecontrol on an ubuntu 9.04 server with Ruby 1.8.7 on it without problems. I don’t recall having any problems getting it working. Are you getting a specific error when you try?

  • http://wwww.twitter.com/raghuonrails Raghu

    I did not really try using since I read it on this page http://cruisecontrolrb.thoughtworks.com/documentation/getting_started that cruise controlrb’s supports only specific to ruby 1.8.6 in the prerequisites section

    Now since you have got it working , I will give a try to it ..! …Can you tell me the version of cruisecontrolrb that you are running with ruby 1.8.7?

    • http://charlesmaxwood.com Chuck

      I’m using the latest version (1.4.0). I’m running ruby version ruby 1.8.7 (2008-08-11 patchlevel 72) on Ubuntu. I’m not sure if I had to modify the code for it or not. (I’m pretty fearless with that when I start getting errors.) Let me know if you need some help.

  • Chris

    Chuck,

    I setup CC for a RoR project last night and had issues with email as well. I discovered what I think is a bug in the CC.rb manual in terms of modifying the site_config.rb file.

    Looking at the source code CruiseControl.rb it seemed that it was looking for site_config.rb in the [cruise_data] directory, not [cruise] (the project directory). I copied the file to [cruise_data] and voila, it worked.

    I’m going to submit a bug report regarding the faulty instructions.

    Chris

  • http://www.joshsoftware.com Amit

    Hello all,
    I am new to to use cruise control.rb.I have some queries.
    1: While running the command i am getting error in Migration which i saw in .cruise/projects/name/build.log
    How can i fix this problem?

    2:Does CC use test database or production since i am getting error on config/environments/production.rb

    3:Now i am using rspec for testing.How can set the path so that as soon as i type command for starting cruise i.e. ./cruise start then it should automatically fetch the testcases from Rspec.
    What i have done is in cruise_config.rb i had done following:
    case project.test
    when ‘MyProject.Quick’ then project.rake_task = ‘spec:controllers’
    # when ‘MyProject.BigBertha’ then project.rake_task = ‘cruise:all_tests’
    else raise “Don’t know what to build for project #{project.test.inspect}”
    end
    Please correct me if i am wrong?

  • http://happyrain.org/ Emily

    Chuck,

    I setup CC for a RoR project last night and had issues with email as well. I discovered what I think is a bug in the CC.rb manual in terms of modifying the site_config.rb file.

    Looking at the source code CruiseControl.rb it seemed that it was looking for site_config.rb in the [cruise_data] directory, not [cruise] (the project directory). I copied the file to [cruise_data] and voila, it worked.

    I’m going to submit a bug report regarding the faulty instructions.

    Chris

  • Pingback: Continuous Integration and CruiseControl.rb — Teach Me To Code … | アプリケーション開発者は、ログに記録

Previous post:

Next post: