Skip to content

Instantly share code, notes, and snippets.

@r10r
Last active November 28, 2016 09:09
Show Gist options
  • Save r10r/5956253 to your computer and use it in GitHub Desktop.
Save r10r/5956253 to your computer and use it in GitHub Desktop.
gitolite hook to 'run hooks per repository'
#!/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
#!/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
@r10r
Copy link
Author

r10r commented Jul 9, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment