Jenkins Pipeline:是否可以避免多次结帐? [英] Jenkins Pipeline: is it possible to avoid multiple checkout?

查看:16
本文介绍了Jenkins Pipeline:是否可以避免多次结帐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了能够集成git 存储库中的 Jenkins 配置.它工作正常,但我问自己是否有办法减少构建时发生的结帐次数.

I've moved a few old Jenkins jobs to new ones using the pipeline feature in order to be able to integrate the Jenkins configuration within the git repositories. It's working fine but I'm asking myself if there is a way to reduce the number of checkout that happens while building.

设置

  • 我有一个与我的 git 存储库相关的 Jenkins 多分支作业
  • 我的 git 存储库中有一个 Jenkinsfile

  • I have a Jenkins multibranch job which is related to my git repository
  • I have a Jenkinsfile in my git repository

#!groovy
node {

  stage 'Checkout'
  checkout scm

  // build project
  stage 'Build'
  ...
}

问题

当我推送到我的远程分支 BRANCH_1 时,会触发多分支 jenkins 作业,我的理解是会发生以下步骤:

When I push to my remote branche BRANCH_1, the multibranch jenkins job is triggered and my understanding is that the following steps happen:

  • 多分支作业为分支索引创建一个 git fetch 并触发与我的远程分支对应的作业:BRANCH_1_job
  • BRANCH_1_job 进行 git checkout 以检索触发分支的 Jenkinsfile
  • Jenkinsfile 被执行并自己生成一个 checkout scm.如果我不这样做,我将无法构建我的项目,因为没有可用的源代码.
  • the multibranch job makes a git fetch for the branch indexing and triggers the job corresponding to my remote branch: BRANCH_1_job
  • BRANCH_1_job makes a git checkout to retrieve the Jenkinsfile of the triggered branch
  • the Jenkinsfile is executed and makes a checkout scm itself. If I don't do it, I can not build my project because no source are available.

所以为了构建我的分支,我最终得到了一个 git fetch 和两个 git checkout.

So for building my branch, I end up with one git fetch and two git checkout.

问题

  • 我是否正确理解了流程?还是我错过了什么?
  • 有没有办法减少git checkout的次数?当我查看 官方示例 时,他们都将签出 scm 作为第一步.我个人认为我不必这样做,因为 jenkins 工作已经必须进行结帐以检索 Jenkinsfile(所以我的来源必须以某种方式在这里).
  • 您不认为一旦 git 存储库包含大量 ref,这些多次签出会导致性能下降吗?
  • Do I understand the process correctly? Or did I miss something?
  • Is there a way to reduce the number of git checkout? When I check the official examples, they all make a checkout scm as first step. I would personally think that I don't have to do it because the jenkins job already had to make a checkout to retrieve the Jenkinsfile (so my sources have to be here somehow).
  • Don't you think these multiple checkouts can cause bad performance as soon as the git repo contains a big number of refs?

谢谢大家

推荐答案

使用普通的 git Jenkins 必须做两次检查:一次让 Jenkinsfile 知道在作业中要执行什么,然后检查实际的存储库内容用于建筑目的.从技术上讲,Jenkins 只需要从 repo 加载一个 Jenkinsfile,但 git 不允许检出单个文件.因此,使用 multibranch 插件的普通 git 无法避免双重结帐.

With plain git Jenkins has to do two checkouts: one to get the Jenkinsfile to know what to execute in the job, and then another checkout of the actual repository content for building purposes. Technically Jenkins only needs to load the one single Jenkinsfile from the repo, but git doesn't allow checkout of a single file. Therefore the double checkout cannot be avoided with plain git using the multibranch plugin.

如果您在 Bitbucket 或 GitHub 上托管 git,那么您可以通过使用其特定的 Jenkins 插件而不是多分支插件来避免重复结帐.

If you host git on Bitbucket or GitHub then you avoid the double checkout by using their specific Jenkins plugins instead of the multibranch plugin.

查看 Jenkins 插件站点以获取 BitbucketGitHub 插件.

See the Jenkins plugin site for Bitbucket and GitHub plugins accordingly.

这些插件使用各自的 Git 提供者的 REST API 来加载单个 Jenkins 文件.因此,从技术上讲,您仍然有双重签出,但第一个是一个简单的 REST 调用来下载单个文件,而不是对整个存储库进行完整的原生 git 签出.

These plugins use the respective Git provider's REST API to load the single Jenkins file. So you technically still have a double checkout, but the first one is a simple REST call to download a single file, rather than doing a full native git checkout of the whole repository.

这篇关于Jenkins Pipeline:是否可以避免多次结帐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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