Recently we switched to Git as our Version Control System solution and I still like it. Coming from “(good) old” CVS we used Jenkins as CI server polling CVS for changes. Besides other nice features and advantages, Git also brings nice commit hooks (well, CVS also does but I finally got to use this nice feature).
Using the post-receive hook you can use your favorite scripting language to do some kick-ass checking when a git commit/push has been made. We first started to use a common approach for every repository and created the post-receive hook like this:
!/bin/bash /usr/bin/curl --user USERNAME:PASS -s \ http://jenkinsci/job/PROJECTNAME/build?token=1qaz2wsx
Configure your Jenkins job to be able to “Trigger builds remotely” and use an authentication token (1qaz2wsx in this example).
Now two issues appear:
- We need to change the PROJECTNAME for every single repository
- In case of more projects/modules in one repository we can’t figure out what specific Jenkins job has to be run.
rodmidde-lan:confluence rodmidde$ git diff-tree --name-status HEAD c299697bd62d89158fd7deb3ebd7d788a215f38d M digiArchief
changeSet=(`git diff-tree --name-status HEAD`)
for(( i=0; i<${#changeSet[@]}; i++))
do
if [ ${changeSet[$i]} == "M" ]
then
projectToBuild=${changeSet[$i+1]}
/usr/bin/curl --user USERMAME:PASS -s \
http://jenkinsci/job/$projectToBuild/build?token=1qzz2wsx
fi
done
Feel free to leave suggestions, improvement and use the script if you like. Questions always welcomed!
It is customary to have just a single solution/project/module in a Git repository, so you should not have to pass an additional value to be able to specify what Jenkins job to use.
If you use multiple solutions in a single repository the history of your entire repo will represent those multiple solutions. It makes it harder to see the history of a single solution.
See http://kiln.stackexchange.com/questions/500/should-i-use-more-than-one-repository for some more background.
Hi Rody,
The new Git plugin version for Jenkins can take an Git URL as argument, and automatically determine the affected builds from that:
http://stackoverflow.com/questions/12794568/how-to-configure-git-post-commit-hook
Hi Tim,
Thanks for the tip, will look into it.