Last active
November 28, 2016 09:09
-
-
Save r10r/5956253 to your computer and use it in GitHub Desktop.
gitolite hook to 'run hooks per repository'
This file contains hidden or 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 | |
server=<server and port> | |
token=<your token> | |
job_name=$(basename `readlink -f $GIT_DIR` .git) | |
job_url=http://${server}/job/${job_name} | |
echo "Trigger jenkins build ${job_name} at ${job_url}" | |
exec wget --quiet ${job_url}/build?token=${token} > /dev/null |
This file contains hidden or 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 | |
# Runs hooks from hooks.d configured in gitolite config | |
# e.g to run the hook `jenkins` for repository `foobar` | |
# | |
# repo foobar | |
# config hooks.run = jenkins | |
# | |
run_hook () { | |
echo -e "\e[1;37m* $4\e[00m " | |
echo $1 $2 $3 | $GIT_DIR/hooks/hooks.d/$4 | |
local exit_code=$? | |
if [ $exit_code -eq 0 ]; then | |
echo -e "\e[1;32msucces\e[00m" | |
else | |
echo -e "\e[1;31mfailure (exit ${exit_code})\e[00m" | |
fi | |
} | |
while read oldrev newrev refname; do | |
if [ "$refname" = "refs/heads/master" ]; then | |
# Global hooks for this repo (ie. set in Gitolite config). | |
hooks=$(git config --get hooks.run) | |
[ -z "$hooks" ] && continue | |
echo -e "\e[1;33mRunning hooks:\e[00m " | |
for hook in $hooks; do | |
run_hook $oldrev $newrev $refname $hook | |
done | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
adapted from http://demonastery.org/2012/09/a-hooking-system-for-gitolite/