3

I have a Java project that's managed using Mercurial, and built with Jenkins. Is there a way to prevent developers from checking in code that breaks the build? I know I can do it with Ant and Mercurial hooks, but is there a way to do it with Jenkins?

Thomas Johnson
  • 10,776
  • 18
  • 60
  • 98
  • 1
    By 'check in', do you mean 'integrate'/'push'? Unless you have a *really* weird Jenkins setup, anything Jenkins is trying (and potentially failing) to build has already been checked in to Mercurial. – Amber Sep 11 '11 at 15:12

3 Answers3

9

Here's a diagram I put together to illustrate the ideas in the other posts:

Two-stage source commit

  • 1
    A text explanation would be helpful, you know, for humans to read, for search engines to index it... BTW Is this image yours? I can't see any copyright or credits. – aalku Sep 12 '11 at 07:19
8

Make your developers pull from a repo (let's name it "master") and push to another one (let's name it "staging"). (Easy with a simple default-push location in the .hgrc)

Jenkins pulls from the staging one and push to the master if the build succeeded, else revert the Jenkin's repository copy.

Only Jenkins should be able to push to the master.

shellholic
  • 5,974
  • 1
  • 20
  • 30
3

No experience with Jenkins here, but a KISS solution that utilizes Mercurial's strengths could go like this:

  • clone master repository
  • pull changes from the developers' machines into the clone
  • run build on the clone
  • if build succeeds, push from clone to master, else delete clone and inform developer
tdammers
  • 20,353
  • 1
  • 39
  • 56
  • Or better yet, revert the clone back to a pristine master state so that it can be re-used for the next build (especially if your repository clone time isn't trivial). – Amber Sep 11 '11 at 15:18
  • I was assuming that you clone within the same file system, on an OS that supports hard links, and with no fancy stuff going on when you clone - in such a situation, clone time *is* trivial, and deleting and re-cloning makes absolutely sure you are using the committed master version as your source. But yes, when clone time isn't trivial, reverting might be a better option. – tdammers Sep 11 '11 at 15:20
  • The CI server isn't necessarily the same machine as the one hosting your repositories, so I just figured I'd point out the option. All depends on the particular setup. :) – Amber Sep 11 '11 at 15:22