OverviewI've found it useful to have my Rails projects running tests on changes to the source code repositories. It helps to raise awareness to test failures. I use cruisecontrol.rb for that purpose and have found it to be useful. However, this post isn't about the merits of continuous integration, but rather about how to setup cruisecontrol.rb under rbenv and have it build your Ruby 2.0.0 projects.
Recently I started working on several Rails 4 projects and at the same time using Ruby 2.0. Unfortunately I ran into several issues with how I was using cruisecontrol.rb to build my projects which up until now have been Ruby 1.8.7 or 1.9.3. Unfortunately, my cruisecontrol.rb setup was choking on Ruby 2.0.0 which was a little frustrating. To simplify my setup a little bit I decided to move from RVM to RBenv to manage my rubies. (side note: Move from RVM to RBEnv if you haven't, you'll probably thank me in the end)
For this post I'm NOT going into how to setup CruiseControl.rb as there is already ample sources for that information. The same is true for setting up rbenv as you can also find many sources of information for that installation as well. If you want to start off with some sources I've used here they are:
How to Configure CruiseControl.rb to use rbenv and build a Ruby 2.0.0-p247 projectNOTE: The following assumes you have a working cruisecontrol.rb setup and in addition you're using rbenv to manage your ruby versions.
First thing you'll need to do is change the cruisecontrol configuration file for your Ruby 2.0.0 project.
Open the file cruise_config.rb located in your .cruise/projects/(project name) folder, with your editor of choice and add the following line:
project.use_bundler = false
This tells cruisecontrol.rb not to use bundler automatically for your project. This is important because you have cruisecontrol.rb running under Ruby 1.8.7 or Ruby 1.9.x and it will cause bundle failure. (side note: I'm running cruisecontrol.rb under 1.9.3-p327 for a year now and it works well)
You'll also want to make sure you are using your own project build command. You should include a line (or un-comment the one in the default file) so that it looks something like the following:
project.build_command = '../build_(your project).sh'
I keep my build file in the same directory as the cruise_config.rb file which is immediately above the work folder cruise control uses to build your project.
So you're cruise_config.rb for the project should look something like this at the end of the file.
After you've made that change you'll need to create or modify your shell script for building your project. My build script looks like this:
It's important that you include the RBENV_VERSION line in your script. This identifies the correct ruby version for your build. Also, note the line rbenv exec bundle install as it is important for your setup to get the bundle setup correctly since you've told cruise control not to use bundler. Your basically forcing the bundle to run using the specific ruby version. I needed this because my Gemfile specified 2.0 and without it and the RBENV_VERSION line I was seeing this:
I have the lines rbenv and rbenv versions in my build file so that I can see the log file contains the correct version information. This was helpful while troubleshooting this setup.
It's also important to note that since you are using bundler, instead of cruisecontrol.rb using it, that you might find that your project already has a .bundle/config file that has identified where your bundle should be stored. You might want to change that file. I had to in order to make sure that the bundle wasn't setup globally for all projects.
Hopefully this helps to get you up and running building Ruby 2.0.0 projects with cruisecontrol.rb