Skip to content

Instantly share code, notes, and snippets.

@jsoref
Forked from magopian/gist:6128849
Last active August 27, 2019 04:31
Show Gist options
  • Save jsoref/861d5584b4b1af9c7248884d5d51ddf2 to your computer and use it in GitHub Desktop.
Save jsoref/861d5584b4b1af9c7248884d5d51ddf2 to your computer and use it in GitHub Desktop.
Local git mirror of github used by private Jenkins
So I've installed a dead simple backup, in /home/USER/git_backup/:
git clone --mirror git@github.com:USER/PROJECT.git
update.sh (launched every 5 minutes by cron):
#/bin/sh
cd /home/USER/git_backup/PROJECT.git
LINES=`git remote update 2>&1 | wc -l`
if [ $LINES -eq 1 ]; then
# only one line "Fetching origin"?
echo "Project didn't change"
else
echo "Project changed, notify jenkins builds"
curl http://JENKINS:8080/git/notifyCommit?url=git@github.com:USER/PROJECT.git
fi
This keeps a perfect copy (mirror) of the PROJECT github repository, and if there's a change when doing the "git remote update", jenkins is notified, and it'll then poll github to check if it should run the builds related to the url provided.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment