Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pre-commit hook for Git when Hudson build has failed

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?

like image 946
Josh Smith Avatar asked Sep 13 '10 03:09

Josh Smith


People also ask

How do you do a pre-commit hook?

Open a terminal window by using option + T in GitKraken Client. Once the terminal windows is open, change directory to . git/hooks . Then use the command chmod +x pre-commit to make the pre-commit file executable.

What is pre-commit hook in git?

The pre-commit hook is run first, before you even type in a commit message. It's used to inspect the snapshot that's about to be committed, to see if you've forgotten something, to make sure tests run, or to examine whatever you need to inspect in the code.

Why use pre-commit hook?

Pre-commit detects problems before they enter your version control system, let's you fix them, or fixes them automatically. The power of the crowd. Easily use hooks other people have created in bash, R, Python and other languages.

How do you skip a pre-commit?

Quick tip if you want to skip the pre-commit validations and quickly want to get a commit out there. To get your commit through without running that pre-commit hook, use the --no-verify option. Voila, without pre-commit hooks running!


1 Answers

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.

like image 57
VonC Avatar answered Sep 26 '22 21:09

VonC