Mercurial offers a variety of hooks, powerful triggers that can be configured to automatically perform automated tasks after an event occurs in a repository. We can leverage Mercurial’s changegroup hook to make Hudson build a project without polling the version control system for changes. This offers some important advantages and disadvantages.
One advantages of triggering builds after hg push is to decrease the load on the Mercurial server and Hudson itself by not polling every 1-60 minutes and use the server when necessary. Of course the fewer projects you have the less this technique buys you. Another advantage is to lower the feedback loop from Hudson; every minute spent waiting for Hudson to poll Mercurial the longer the feedback loop gets.
There are some important disadvantages to this technique too by introducing additional coupling between your CI server and your version control server (VCS). While Hudson always knows about your VCS now your VCS knows about Hudson. Another disadvantage is most likely you already have Hudson setup to poll Mercurial, so there’s time to configure both ends of the process.
Configuring this Mercurial hook really is easy, just edit the file YOUR_REPO/.hg/hgrc located on your Mercurial server and add the following:
changegroup.hudson = curl http://hudson_url/job/project_name/build?delay=0sec
You will need to change hudson_url to the URL of your Hudson server and project_name to the Hudson project you wish to build.
Be sure to add a file, commit, and push to test your hook. You should see the project instantly added to the build queue.
Update 2010-07-14: Mirko has posted a variation to this post that is worthwhile.