如何使用Jenkinsfile备份Jenkins [英] How to Backup Jenkins using Jenkinsfile
问题描述
如何使用不带插件的Jenkinsfile进行Jenkins作业配置备份?
How To do Jenkins jobs configuration backup using Jenkinsfile without plugins?
要备份的东西:
- 系统配置{jenkins}
- 职位配置
推荐答案
我们对插件备份解决方案不满意,因此我们在主服务器上运行了一个自由式shell步骤作业(通常是不行,因此仅允许托管特殊命令)
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}
中,您要备份:
# 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帖子了解常规信息,然后根据需要从列表中重新安装.如果选择的话,将备份插件和更新与其余备份分开,但是一起备份.
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文件夹,而无需读取整个目录树,也无需跳过builds
和htmlreports
等.
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屋!