Triggering Hudson builds with Mercurial hooks

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:

[hooks]
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.

If your Hudson installation is using security you will need to do things a little differently; see authenticating scripted clients for details. If your job is parameterized you can do that too.

Update 2010-07-14: Mirko has posted a variation to this post that is worthwhile.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Bloglines
  • Google Bookmarks
  • Technorati
  • TwitThis
Tags: , , , ,  

2 Comments

  1. Hey!

    Perhaps you wanna take a look to this piece of code.

    http://pypi.python.org/pypi/hghudson

  2. Is there anything similar for git and github?

Leave a Reply

Comments are closed.