- Create an empty repo in your Git provider of choice (GitHub, Bitbucket, Gitlab). I usually call it
jenkins-config
. - Login to your Jenkins machine, cd into JENKINS_HOME (e.g. /var/lib/jenkins).
- To avoid permissions issues do this as the same user Jenkins runs as.
git init
and setup your remote origin.- In the Jenkins interface, create job
StoreConfigInGit
and paste the contents ofrun.sh
in anExecute Shell
block. - One it runs successfully, configure it to "Build Periodically"
@daily
Created
March 1, 2020 16:38
-
-
Save raymyers/947b99f51e575aba92a1b525ae1e88a5 to your computer and use it in GitHub Desktop.
Backup Jenkins Config Daily Job
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
# Last tested in Jenkins 2.22 | |
* | |
!/.gitignore | |
!/*.xml | |
!/nextBuildNumber | |
!/jobs | |
!/jobs/* | |
!/jobs/*/*.xml | |
/jobs/*/disk-usage.xml | |
/jobs/*/builds | |
!plugins | |
!plugins/*.jpi | |
!/users | |
!/users/**/ | |
!/users/**/*.xml |
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
cd $JENKINS_HOME | |
git config --global user.email "[email protected]" | |
git config --global user.name "Jenkins" | |
git add -A . | |
git status | |
git diff-index --quiet HEAD || git commit -m "Automated Jenkins commit" | |
git push origin master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment