Skip to content

Instantly share code, notes, and snippets.

@rlespinasse
Created January 4, 2016 15:09
Show Gist options
  • Save rlespinasse/bc38d2c10e35337229a6 to your computer and use it in GitHub Desktop.
Save rlespinasse/bc38d2c10e35337229a6 to your computer and use it in GitHub Desktop.
Jenkins configuration backup
# untrack all files and folders
/*
# Except the jenkins configuration
!/config.xml
# Except the jenkins plugin configurations
!/hudson*.xml
# Except this file
!/.gitignore
# Except jenkins job configurations (the config.xml files under sub-folder of /jobs)
!/jobs
!/jobs/*
/jobs/*/*
!/jobs/*/config.xml
!/jobs/*/jobs
!/jobs/*/jobs/*
/jobs/*/jobs/*/*
!/jobs/*/jobs/*/config.xml
# Except jenkins users configurations (the config.xml files under sub-folder of /users)
!/users
!/users/*
/users/*/*
!/users/*/config.xml
#!/bin/bash -e
# Jenkins Configuraitons Directory
cd $JENKINS_HOME
git_status="`git status -unormal 2>&1`"
if [[ "$git_status" =~ Not\ a\ git\ repo ]]; then
echo
echo "NOT A GIT REPOSITORY"
echo
exit 1
elif [[ "$git_status" =~ nothing\ to\ commit ]]; then
echo
echo "NOTHING CHANGED !"
echo
exit 0
else
# setup user name and email (if necessary)
#export GIT_AUTHOR_NAME=""
#export GIT_AUTHOR_EMAIL=""
#export GIT_COMMITTER_NAME=""
#export GIT_COMMITTER_EMAIL=""
git add --all .
git commit -am "automated jenkins configuration backup
by build ${BUILD_TAG}
on ${JENKINS_URL}"
git push -q origin master
exit 0
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment