Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example of a script for backing up Jenkins config in git.
# Copies certain kinds of known files and directories from a given Jenkins master directory
# into a git repo, removing any old ones, adds 'em, commits 'em, pushes 'em.
set -ex
if [ $# -ne 3 ]; then
echo usage: $0 jenkins_home git_repos_url git_repos_name
exit 1
rm -rf ${GIT_REPOS_NAME}
git clone ${GIT_REMOTE_URL}
rsync -av --delete --exclude="jobConfigHistory" \
--exclude="war" \
--exclude="config-history" \
--exclude=".hudson" \
--exclude=".ivy2" \
--exclude=".m2" \
--exclude="lost+found" \
--include="*config.xml" \
--include="jobs/*/builds/*/log" \
--include="users/*" \
--include="*.hpi" \
--include="*.jpi" \
--include="*pinned" \
--include="*disabled" \
--include="scriptler/*" \
--include="secrets/*" \
--include="*.xml" \
--include="*.key" \
--exclude="*" \
--prune-empty-dirs ${JENKINS_HOME}/ .
git add -A
git commit -m "Jenkins ${JENKINS_MASTER} config backup for $(date)"
git push origin master
## example
# ./ jenkins@ deepin-jenkins-git

This comment has been minimized.

Copy link

@Lake-end Lake-end commented Dec 18, 2017

rm -rf ${GIT_REPOS_NAME}
You are one messed up paramater away from deleting your Jenkins_home

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment