Skip to content

Instantly share code, notes, and snippets.

@rudolfovich
Forked from alexsplashex/Jenkins backup script
Last active August 18, 2020 16:21
Show Gist options
  • Save rudolfovich/8e3f5363b590e303fa7fcf0bc49225a8 to your computer and use it in GitHub Desktop.
Save rudolfovich/8e3f5363b590e303fa7fcf0bc49225a8 to your computer and use it in GitHub Desktop.
#!/bin/bash
# source: https://medium.com/@_oleksii_/how-to-backup-and-restore-jenkins-complete-guide-62fc2f99b457
# Jenkins Configuraitons Directory
cd $JENKINS_HOME
git fetch
git merge --commit
# Add general configurations, job configurations, and user content
git add -- *.xml
git add -- userContent/*
find jobs/ -name config.xml -exec git add -- {} \;
find jobs/ -name state.xml -exec git add -- {} \;
find jobs/ -name name-utf8.txt -exec git add -- {} \;
find jobs/ -name svnexternals.txt -exec git add -- {} \;
find jobs/ -name scm-revision-hash.xml -exec git add -- {} \;
find jobs/ -name scm-last-seen-revision-hash.xml -exec git add -- {} \;
find plugins/ -iname '*.jpi' -exec git lfs track {} \;
# find plugins/ -iname '*.jpi' -exec git add --ignore-errors -- {} \;
git add -- plugins/
# only add user configurations if they exist
if [ -d users ]; then
user_configs=`ls users/*/config.xml`
if [ -n "$user_configs" ]; then
git add $user_configs
fi
git add "users/users.xml"
fi
# mark as deleted anything that's been, well, deleted
to_remove=`git status | grep "deleted" | awk '{print $3}'`
if [ -n "$to_remove" ]; then
git rm --ignore-unmatch $to_remove
fi
git commit --all -m "BugId:none Jenkins Automated Backup: ${BUILD_TAG}"
git push -q -u origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment