How to Backup Jenkins using Jenkinsfile

拈花ヽ惹草 提交于 2021-01-26 03:04:50

问题


How To do Jenkins jobs configuration backup using Jenkinsfile without plugins?

things to be backup :

  1. system configuration {jenkins}
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!