How to call Rake from CruiseControl.Net

July 25, 2007

Rake gives you a tremendous power when it comes to automating tasks for any kind of applications, including .Net applications. For those .Net applications, I only delegate the compilation step to MSBuild. All the rest is handled through Rake itself, which may do the job itself and/or delegate stuff to other binaries (things like wget, winscp, unzip, gunzip, putty).

I usually setup a CruiseControl.Net instance when I start a .Net project. When I started using Rake, I wanted to be able to call Rake from CruiseControl.Net.

Here’s an extract of a working ccnet.config file calling Rake. The paths are absolute to ensure it doesn’t rely on a PATH variable, which causes troubles when CCNet is running as a service:

<exec>
  <executable>
    C:\ruby\bin\rake.bat
  </executable>
  <buildArgs>
    ci WORKSPACE=C:\ccnet\MyProject
  </buildArgs>
  <baseDirectory>
    C:\ccnet\MyProject
  </baseDirectory>
  <buildTimeoutSeconds>300</buildTimeoutSeconds>
</exec>

You can call as many Rake tasks as you like on the same row. Properties (key=value) can be passed along, and retrieved later in the Rakefile using ENV['key'].

This setup gave me the best of both worlds: MSBuild for what it does well (compiling .Net solutions), and Rake for everything else (deployment, packaging, file manipulation, running tests, database migrations).