首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用Jenkins作业备份Jenkins主目录

用Jenkins作业备份Jenkins主目录
EN

Stack Overflow用户
提问于 2017-06-26 18:47:37
回答 1查看 2.2K关注 0票数 1

我已经看过几种备份Jenkins主目录的方法。其中一个更有趣(而且看起来是完整的)的方法是配置Jenkins作业,它将Jenkins主目录备份到源代码管理。

在备份过程中,我试图弄清楚到底需要执行什么(通过'execute‘构建步骤)。我们目前使用BitBucket进行源代码管理(GIT),并有一个Jenkins和四个Jenkins /从构建节点。

先决条件

  • 将Jenkins主目录初始化为git。

备份Jenkins的步骤

  1. CD到Jenkins主目录。
  2. 将Jenkins Home本地存储库中所有更改的文件提交给存储库的主分支。
  3. 将更改从本地存储库推送到BitBucket存储库。
  4. 鱼鳍。在需要备份的情况下,Jenkins home的最新副本现在存储在源代码管理中。

因此,对于那些以前使用这种方法对Jenkins进行自动备份的人,我有几个问题:

  • 当分布式构建(代理/从)系统就位时,Jenkins Home目录的备份是否足以备份Jenkins?
  • 在Jenkins目录的备份中是否应该排除任何文件/目录?
  • 将Jenkins目录初始化为GIT存储库会不会对Jenkins产生任何不良影响?
  • 我注意到一些教程提到创建用户凭据Jenkins在连接到BitBucket时将使用。这是怎么回事?

任何其他建议也是受欢迎的。

EN

回答 1

Stack Overflow用户

发布于 2017-07-25 13:16:23

在工作中,您可以添加BitBucket凭据。但是我所做的就是让作业文件夹成为一个.git回购,并且我经常手动提交它。

您还可以为您运行我在网上找到的bash脚本:巴什脚本来完成这个任务。

代码语言:javascript
复制
#!/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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44766649

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档