6

I'm trying to figure out how to write a pre-commit hook for Git that checks the status of my Hudson build. If the previous build failed, it should disallow anyone from committing without first writing a specific line, e.g. "fixed build."

EDIT:

The first answerer has provided one side of the coin: the Hudson API.

I now need the other side. How do I write the pre-commit hook in Git?

Josh Smith
  • 14,674
  • 18
  • 72
  • 118
  • Just thinking of an interesting use case. Suppose Hudson fails. Two developers are working on the code, one on the fix and the second one on the next feature. In your case the fix developer needs to check the code in first. The second developer has to wait until Hudson successfully rebuilds. Not sure if that might be an issue for you (highly depends on the build times). In my opinion you are better of, giving the project leader an monitor, that always shows the most current build status. He will become active if the build is broken for an extended period of time. – Peter Schuetze Sep 13 '10 at 14:49
  • Build times at the moment are very low (on the order of several minutes) so that shouldn't be an issue...yet. – Josh Smith Sep 13 '10 at 19:05
  • Just a comment (not sure if it can be applied to your situation): see also http://stackoverflow.com/questions/3209208/what-is-the-cleverest-use-of-source-repository-that-you-have-ever-seen/3209767#3209767 – VonC Sep 13 '10 at 19:34

1 Answers1

2

As mentioned in this blog post, Hudson has a discoverable API, through its Remote Access API.

http://myhudson.example.com/job/MyJob/api

By using a combination of:

  • wget (available on Unix or Windows)
  • parsing

you can extract the status of the latest build.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Very nice is Hudson's support for XPath. I used it to query the artifact Names to download specific artifacts in a second step. In you case a single wget call should give you the right information. – Peter Schuetze Sep 13 '10 at 14:43
  • Thanks for this. I've edited my question to now reflect that I'm only looking for how to write the pre-commit hook in `Git` now. Feel free to edit your answer. – Josh Smith Sep 13 '10 at 19:19