How to make git commit to trigger run a Jenkins job
TweetPosted on Friday Feb 21, 2014 at 06:02PM in Technology
Environment
- Jenkins 1.551
- git version 1.8.3.4 (Apple Git-47)
- OS X 10.9.1
Try using curl
- In this setup, there is no authentication at Jenkins.
curl -X POST http://localhost:18080/job/BuildAndTestHead/build
- Let's try with dump-header option.
kyle-no-MacBook:Jenkins kyle$ curl -D - -X POST http://localhost:18080/job/BuildAndTestHead/build HTTP/1.1 201 Created Location: http://localhost:18080/queue/item/4/ Content-Length: 0 Server: Jetty(8.y.z-SNAPSHOT) kyle-no-MacBook:Jenkins kyle$
Configure a hook of repository
- Create a file named “post-commit” in .git/hooks directory.
kyle-no-MacBook:hooks kyle$ pwd /Users/kyle/gits1/hellojenkins/.git/hooks kyle-no-MacBook:hooks kyle$ ls -l total 8 -rwxr-xr-x+ 1 kyle staff 73 2 23 10:50 post-commit kyle-no-MacBook:hooks kyle$ cat post-commit #!/bin/sh curl -X POST http://localhost:18080/job/BuildAndTestHead/build kyle-no-MacBook:hooks kyle$
- Now it runs automatically when we commit using git command from cli.
Remarks
- According to [3], It doesn't work when we commit with Eclipse.
- So, we might have to config Jenkins to poll the repository periodically.
References
Tags: jenkins