-
-
Save vensder/a31ed54b6036a61d3296b318d60ef564 to your computer and use it in GitHub Desktop.
Gitolite post-receive hook to trigger builds of Jenkins / Git jobs
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
#!/bin/bash | |
# place script in hooks dir in repo, rename post-receive-jenkins to post-receive, chmod +x file | |
# Gitolite [https://github.com/sitaramc/gitolite] | |
# Jenkins Git Plugin [https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin] | |
# GL_REPO will contain the short relative path of the repository being pushed to, e.g. "projects/component-1", so transform it into the Git URL format that your Jenkins build jobs follow: | |
REPOSITORY_URL=git@gitolite.example.com:$GL_REPO | |
# Jenkins Git plugin notification URL -- update host as appropriate: | |
TRIGGER_URL=http://jenkins.example.com:8080/git/notifyCommit\?url=$REPOSITORY_URL | |
# You shouldn't need to modify anything beyond this line. | |
while read oldrev newrev ref; do | |
if [[ $ref == refs/heads/* ]]; then | |
branch=${ref:11} | |
echo -n "Notifying Jenkins of changes to $REPOSITORY_URL branch=$branch commit=$newrev... " | |
curl -m 5 --silent "$TRIGGER_URL&branches=$branch" || echo Failed to notify Jenkins | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment