Skip to content

Instantly share code, notes, and snippets.

@pcholakov
Created February 2, 2014 16:13
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save pcholakov/8770648 to your computer and use it in GitHub Desktop.
Save pcholakov/8770648 to your computer and use it in GitHub Desktop.
Gitolite post-receive hook to trigger builds of Jenkins / Git jobs
#!/bin/bash
# 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