如何使用Jenkinsfile备份Jenkins

如何使用不带插件的Jenkinsfile进行Jenkins作业配置备份?

要备份的东西:

  1. 系统配置{jenkins}
  2. 职位配置
CS_DN_CS_DN 回答:如何使用Jenkinsfile备份Jenkins

我们对插件的备份解决方案不满意,因此我们在主服务器上运行了一个自由式shell步骤作业(通常是不行,因此仅允许诸如备份之类的托管特殊任务在其中运行),其中包含一个简单的tar cmd,一个用于系统配置(xml,键等),用于作业(不包括日志'n东西)。


系统备份

${JENKINS_HOME}中,您要备份:

# 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

插件

我认为不需要存储caches,updates,plugins,等。

我们单独管理插件,因此我们仅存储所使用插件的版本列表-请参阅DevOps post for the groovy并在必要时从列表中重新安装。如果选择的话,将备份插件和更新与其余备份分开,但是一起备份。


工作备份

我们实际上并不关心构建日志,但是我们确实关心配置(config.xml)和下一个内部版本号(nextBuildNumber)。我们使用以下两步tar构建列表;这使我们可以遍历任意深度的Jenkins文件夹,而无需读取整个目录树,跳过buildshtmlreports等。

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://www.f2er.com/3098265.html

大家都在问