I initialze $JENKINS_HOME as a git repository with the following .gitignore file.
#global types to ignore
*.swp
#Only get job configs and ignore other data
!jobs/*
jobs/*/*
!jobs/*/config.xml
#Ignore expanded plugins folders because we only want jpi files
#plugins/*/*
#Ignore all plugins
plugins
#Ignore logs
logs
There is a cron job which automatically updates this repository.
@daily /app/builder/dailycommit.sh
The contents of dailycommit.sh is the following.
#!/bin/bash
#Sam Gleske (sag47)
#Tue Mar 4 14:35:59 EST 2014
#Red Hat Enterprise Linux Server release 6.5 (Santiago)
#Linux 2.6.32-431.3.1.el6.x86_64 x86_64
#GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
if [ -z "${JENKINS_HOME}" ];then
echo "JENKINS_HOME not set." 1>&2
exit 1
fi
if [ ! "${USER}" = "jboss" ];then
echo "Must be jboss user to run daily commit." 1>&2
exit 1
fi
export PATH="/usr/local/bin:${PATH}"
cd "${JENKINS_HOME}"
git add .
git add -u
git commit -m "daily commit $(date '+%a %m/%d/%Y')"
git push origin master
Keep in mind a backup could be something as simple as backing up only the
config.xmlvia git. Here's a better.gitignorefile one could use for$JENKINS_HOMEconfig backups. This accounts for the Cloudbees folder plugin jobs as well unlike the original.How does it work? The
.gitignorefile works from top to bottom. Following rules override former rules. So when a rule ignores a file and a following rule excludes it from being ignored the following rule takes precedence.