Created
May 19, 2011 21:02
-
-
Save evilchili/981734 to your computer and use it in GitHub Desktop.
a sample post-receive hook that implements automatic branch building
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# hook setup | |
read oldrev newrev refname | |
job="MyJenkinsJob" | |
jenkins_url="http://jenkins/job" | |
jenkins_token="seeeeekrit" | |
# what branch are we building? | |
regex='refs/heads/(.*)' | |
if [[ $refname =~ $regex ]]; then | |
target_branch="${BASH_REMATCH[1]}" | |
fi | |
# define autobuild_enabled somewhere else | |
if [[ $autobuild_enabled ]] ; then | |
function trigger_build { | |
echo "Automatically scheduling new build against origin/$target_branch: $jenkins_url/$job" | |
wget -q -O - "$jenkins_url/$job/buildWithParameters?token=$jenkins_token&BRANCH=$target_branch" > /dev/null | |
} | |
case "$change_type" in | |
create) | |
if expr "$newrev" : '0*$' >/dev/null; then | |
echo "$refname is newly created, so not triggering a build." | |
else | |
trigger_build | |
fi | |
;; | |
update) | |
trigger_build | |
;; | |
delete) | |
echo "$refname is being deleted, so not triggering a build." | |
;; | |
esac | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment