Skip to content

Instantly share code, notes, and snippets.

@samukasmk
Created January 17, 2014 17:54
Show Gist options
  • Save samukasmk/8478134 to your computer and use it in GitHub Desktop.
Save samukasmk/8478134 to your computer and use it in GitHub Desktop.
Cron Job like git hook, to inform the Jenkins|Hudson ScriptTrigger Plugin to do a build. - by Samuel Maciel Sampaio
#!/bin/bash#
#
# check_git_remote_changes.sh
# By: Samuel Maciel Sampaio <20140115>
#
# Cron Job like git hook, to inform the Jenkins|Hudson
# ScriptTrigger Plugin to do a build.
# Plugin: https://wiki.jenkins-ci.org/display/JENKINS/ScriptTrigger+Plugin
GIT_REPO_FOLDER=$1
if [ -z "$GIT_REPO_FOLDER" ]; then
echo "usage: $0 <GIT_REPO_FOLDER>";
exit 1;
fi
fetch_output=$(
git --git-dir "$GIT_REPO_FOLDER/.git" \
--work-tree "$GIT_REPO_FOLDER" \
fetch --dry-run 2>&1
)
echo $fetch_output | grep "^From"
grep_exit_code=$?
if [ "$grep_exit_code" -eq "0" ]; then
git --git-dir "$GIT_REPO_FOLDER/.git"\
--work-tree "$GIT_REPO_FOLDER" \
fetch
git --git-dir "$GIT_REPO_FOLDER/.git"\
--work-tree "$GIT_REPO_FOLDER" \
fetch --tags
exit 0
else
exit 2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment