A few months ago, I discovered the wonders of continuous integration. The idea behind continuous integration is very simple: when a commit is made (or every few minutes, but more often than daily), compile and test the code and perhaps do a few more things. Generally, you want your continuous integration builder to do its thing after every single commit. At this point, I can sense all the IS/IT people out there screaming “OMG! Too many resources!” And yes, it does take a lot of resources - a compile and test for a decent size project can take 10 minutes at full power on one of the servers here at Molecular. But continuous integration is most definitely worth the trouble!
When working on a large team (there are probably ~15 developers in diffferent areas working on the project I am on now), the repository can frequently be in an unstable state, meaning either the code does not compile, or the tests don’t pass so the thing doesn’t work. This can happen because someone forgets to commit a file (I’ve done that many times), someone makes a typo, or someone just doesn’t make sure the code works before they commit. Needless to say, it can be really annoying to update your local copy and start to work, then run into errors, only to find out you didn’t create them. Then, as an annoyed developer, you want to find someone to blame (and also to fix the situation so you can resume your work), so you email the everyone you suspect, or walk around the building. That adds up to a lot of lost productivity!
Continuous integration solves this problem by making sure that every commit in the repository results in a working, stable, tested build. If it doesn’t, the developer who broke the build gets a nasty automated email, and everyone else gets notified that the repository isn’t in a usable state. That way, the other developers know not to update their local code. Finally, when the problem is resolved, everyone gets an email saying things are a-okay again.
The value of continuous integration is proportional to the quality of the test cases the team writes. The more test cases, and the more code coverage, the more likely a bug will be caught and reported by the continuous integration system right after it is committed. This minimized regressions to almost nothing (assuming the team is really diligent with their test cases).
The CI server can also do other things besides build and test. In the case of my project, the artifacts are published to a central repository so others can grab them. For example, one component we built is an interface to Solr. Whenever the CI server builds the Solr interface project, it publishes the resultant jar file to our maven repository (Artficatory), so now the developers who depend on the Solr interface will automatically grab the latest snapshot, but do not need to compile it themselves, saving everyone time.
Another really cool thing you can do with a continuous integration server is generate documentation, and run bug scanners, as part of the build. My project generates javadoc, and runs Cobertura, PMD & CPD, and a host of other tools against the code, and publishes all this to a web site. Those tools do take a while to run - so developers tend not to run them too often. Having them as part of CI ensures that the latest documentation, code coverage, and bug suspects are always available.
Don’t let my Java example lead you to any premature conclusions - CI can be used for anything from Javascript to Haskell to C#. If you can build it from the command line, you can use CI (and even Visual Studio projects can be built from the command line now).
Finally, CI can be fun. I just hooked up an X10 remote control lighting kit I had laying around to a lamp I have sitting on my desk. Combine that with a ruby script, and in about 30 minutes (I spend 20 minutes finding a lamp), I setup a build status beacon in my cube. Presently it is on, indicating the build is broken… so I won’t be updating from the repository quite yet.
In case you were wondering, here at Molecular we use Hudson. It’s incredibly easy to install (drop the war into Tomcat, and you’re done), adding projects is quick and easy, and it supports Maven, Ant, msbuild, and ruby right in the web UI. This ease of administration and use is why I chose it over Continuum, for example.
With that, I heartily recommend CI for all projects. It’s very easy to set up, and well worth the small initial investment if you can avoid the common situation of developers running around searching for the person who broke the build.