Skip to content

Instantly share code, notes, and snippets.

@vensder
Forked from pcholakov/post-receive-jenkins
Last active February 7, 2017 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vensder/a31ed54b6036a61d3296b318d60ef564 to your computer and use it in GitHub Desktop.
Save vensder/a31ed54b6036a61d3296b318d60ef564 to your computer and use it in GitHub Desktop.
Gitolite post-receive hook to trigger builds of Jenkins / Git jobs
#!/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