Green & Red Local Builds (adding colour to the local build process)

build.JPGWell, who doesn't write tests and do continuous integration (CI) these days? Whether you use one of the many Cruise Control variants, or Team City or some other tool, you most likely get a handy colour coding of builds as either green or red (ie, good, or bad). But, you can take this a step further!

redbuild.JPGOften on .NET projects, we have a little batch file that we run before checking in (often with a pause at the end so it can be run from a shortcut), to confirm that no tests are broken locally. Well, it's not much fun peering at the ugly Nant output (or whatever build system you use). Instead, it is quite easy to add a couple of lines to your batch file and change the colour of the console to bright Red or bright Green depending on the success of the local build. It is great for telling what the result was at a glance. I can't claim credit the idea - it was something we used at EDI for our custom build system, but here's some batch file code I whipped up which I can claim is all mine, every last GOTO of it! Enjoy 🙂

The following code uses NAnt, but you can replace it with MsBuild or any other build tool that returns a status code.

@echo off

color 07

tools\\nant\\NAnt.exe %*

IF ERRORLEVEL 1 goto RedBuild
IF ERRORLEVEL 0 goto GreenBuild

color 4F
goto TheEnd

color 2F




2 responses to “Green & Red Local Builds (adding colour to the local build process)”

23 02 2009
Fabio Pereira » Red and Green Maven Build (08:20:17) :

[...] have adapted on our project James Crisp’s cool idea about changing the color of the command when the build fails or passes… Now it works for [...]

23 02 2009
Fabio Pereira (08:42:10) :

Hey Crisp!
We have adapted it to maven, as I told you...
I've posted about it...

Cooooooool mate!

Thanks a lot...