用詹金斯工作备份詹金斯主目录
问题描述:
我看了几种备份詹金斯主目录的方法。更有趣的(看似完整的)方法之一是配置一个Jenkins作业,将Jenkins主目录备份到源代码控制。用詹金斯工作备份詹金斯主目录
我想清楚在备份过程中需要执行什么操作(通过“执行shell”构建步骤)。我们目前使用BitBucket进行源代码控制(GIT),并且有一个Jenkins Master和四个Jenkins代理/从构建节点。
先决条件:
- 初始化詹金斯主目录作为一个git回购。
步骤来备份詹金斯:
- CD詹金斯主目录。
- 将Jenkins Home本地存储库中的所有已更改文件提交到存储库的主分支 。
- 将更改从本地存储库推送到BitBucket 存储库。
- FIN。 Jenkins主页的最新副本现在存储在源控件中,以备我们需要备份时使用。
所以我对那些人之前已经使用这种方法进行詹金斯的自动备份几个问题:
- 是詹金斯Home目录的备份独自足以备份詹金斯 当分布式构建(代理/奴隶),系统是否到位?
- Jenkins 主目录的备份中是否应该排除任何文件/目录?
- 将詹金斯主目录初始化为GIT存储库对Jenkins而言有任何 不利影响?
- 我注意到一些教程提到创建用户凭证 Jenkins将在连接到BitBucket时使用。这个怎么用?
任何额外的建议也欢迎。
答
在工作上,您可以添加BitBucket凭据。但是我为我做的是将作业文件夹设置为.git repo,并且我经常每隔一段时间手动提交一次。
你也可以做一个工作,为你做这个运行bash脚本我在网上找到:Bash Script
#!/bin/bash
# Setup
#
# - Create a new Jenkins Job
# - Mark "None" for Source Control Management
# - Select the "Build Periodically" build trigger
# - configure to run as frequently as you like
# - Add a new "Execute Shell" build step
# - Paste the contents of this file as the command
# - Save
#
# NOTE: before this job will work, you'll need to manually navigate to the $JENKINS_HOME directory
# and do the initial set up of the git repository.
# Make sure the appropriate remote is added and the default remote/branch set up.
#
# Jenkins Configuraitons Directory
cd $JENKINS_HOME
# Add general configurations, job configurations, and user content
git add -- *.xml jobs/*/*.xml userContent/*
# only add user configurations if they exist
if [ -d users ]; then
user_configs=`ls users/*/config.xml`
if [ -n "$user_configs" ]; then
git add $user_configs
fi
fi
# mark as deleted anything that's been, well, deleted
to_remove=`git status | grep "deleted" | awk '{print $3}'`
if [ -n "$to_remove" ]; then
git rm --ignore-unmatch $to_remove
fi
git commit -m "Automated Jenkins commit"
git push -q -u origin master