Blog

Capturing Rake return codes

Based on Martin Fowlers whole pitch on declarative versus imperative builds, I converted a basic Ruby script into a Rake based script. However, the one gotcha I hit was that running rake dist, the return code wasnt returned. Yes, rake would say it failed:

(in E:/irocket/continuum/working-directory/6)rake aborted!I should fail the buildE:/irocket/continuum/working-directory/6/rakefile:310

We are using Continuum, a very simple to set up CI tool, and it requires whatever script it calls to return 0 on success, and > 0 on failure. So even though Rake would say the build failed, it always return 0. It turns out that some people have run into this problem:

I didnt want to hack up my rake.bat and rake.cmd files, so instead I am calling ruby directly:

ruby -x e:irocketrubybinrake.bat dist

Hopefully the next version of Rake will have this resolved! The Continuum project went through this same pain for Ant and Maven scripts, and have posted their fixed batch files.