问题
How To do Jenkins jobs configuration backup using Jenkinsfile without plugins?
things to be backup :
- system configuration {jenkins}
- jobs configuration
回答1:
We were not happy with the plugins backup solutions, so we have a freestyle shell step job run on master (usually a no-no, so only allow managed special task like backup to run there) with a simple tar cmd, one for system config (xmls, keys, etc), one for jobs (excluding logs 'n stuff).
System backup
In ${JENKINS_HOME}
, you'll want to backup:
# Jenkins launcher
jenkins
jenkins.conf
#Jenkins install states
jenkins.install.*
# secrets
secret.key*
identity.key.enc
init.groovy # if you have one
# ALL the configuration files
*.xml # This covers the config.xml and all the plugins xmls
#
# directories:
secrets
init.groovy.d # if you have one
nodes
users
userContent # if you have content there
Plugins
I don't believe there is a need to store caches, updates, plugins,
etc.
We manage plugins separately so we simply store the versioned list of plugins used - see this DevOps post for the groovy and reinstall from the list if necessary. If you choose, backup plugins and updates separately from the rest but together.
Jobs backup
We don't really care about the builds logs, but we do care about the configuration (config.xml
) and next build number (nextBuildNumber
). We use the following 2-step tar to build the list; this allows us to traverse Jenkins folders of arbitrary depth without reading the entire directory tree, skipping builds
and htmlreports
, etc.
find ${JENKINS_HOME}/jobs/*/* -type d \( -name builds -o -name htmlreports \) -fprint /dev/null -prune \
-o -type f \( -name config.xml -o -name nextBuildNumber \) -print > jenkins-jobs.lst
tar -czf Jenkins.jobs.${label}.tgz -C ${JENKINS_HOME} --no-recursion --files-from=jenkins-jobs.lst
来源:https://stackoverflow.com/questions/58869307/how-to-backup-jenkins-using-jenkinsfile