如何使用 Jenkinsfile 备份 Jenkins [英] How to Backup Jenkins using Jenkinsfile

查看:17
本文介绍了如何使用 Jenkinsfile 备份 Jenkins的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在没有插件的情况下使用 Jenkinsfile 进行 Jenkins 作业配置备份?

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

要备份的东西:

  1. 系统配置 {jenkins}
  2. 作业配置

推荐答案

我们对插件备份解决方案不满意,所以我们在 master 上运行了一个自由式 shell step 作业(通常是禁止的,所以只允许托管特殊像备份这样的任务在那里运行)使用一个简单的 tar cmd,一个用于系统配置(xmls,密钥等),一个用于作业(不包括日志'n 东西).

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).

${JENKINS_HOME} 中,您需要备份:

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

插件

我认为不需要存储 缓存、更新、插件、 等.

我们单独管理插件,因此我们只存储使用的插件的版本列表 - 请参阅此 DevOps 帖子以了解 groovy 并在必要时从列表中重新安装.如果您愿意,请将插件和更新与其他插件和更新分开备份.

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.

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

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

这篇关于如何使用 Jenkinsfile 备份 Jenkins的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆