简体   繁体   English

Jenkins 管道:scm checkout 浅拷贝失败

[英]Jenkins Pipeline: scm checkout shallow copy fails

I am using Jenkins file to build a pipeline.我正在使用 Jenkins 文件来构建管道。 I am trying to clone the reference repository using DSL like below.我正在尝试使用如下 DSL 克隆参考存储库。

checkout(
[$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, 
extensions: [[$class: 'CloneOption', depth: 1, noTags: false, reference: '', shallow: true]], 
submoduleCfg: [], 
userRemoteConfigs: [[url: 'git@bitbucket.org:user_team/infrastructure-as-code.git']])

and while the pipeline is being executed, it is being translated to this当管道正在执行时,它正在被转换成这个

git fetch --tags --progress git@bitbucket.org:userteam/infrastructure-as-code.git +refs/heads/*:refs/remotes/origin/* --depth=1

This clones the whole repository on my Jenkins server.这会在我的 Jenkins 服务器上克隆整个存储库。 I just want to obtain a shallow copy of my repo so that I could save my Jenkins server from space crunch.我只想获得我的 repo 的浅拷贝,以便我可以从空间紧缩中拯救我的 Jenkins 服务器。 Please help here.请在这里帮忙。

I am using: Jenkins version: 2.58,我正在使用:Jenkins 版本:2.58,

Plugins:插件:

Pipeline SCM Step: 2.4流水线 SCM 步骤:2.4

Git: 3.3.0吉特:3.3.0

I think you are misunderstanding the meaning of shallow clone.我认为您误解了浅克隆的含义。
Shallow clone will still clone the entire repository.浅克隆仍将克隆整个存储库。
The difference will be that history will be truncated to the specified number of commits (in your case 1, since you have mentioned depth to be one.) It can save you a lot of space and time.不同之处在于历史将被截断为指定的提交次数(在您的情况下为 1,因为您已经提到深度为 1。)它可以为您节省大量空间和时间。

For more information please follow this link: git-clone#Documentation有关更多信息,请点击此链接: git-clone#Documentation

For instance, see the below image where I am cloning same repository ( https://github.com/spring-cloud/spring-cloud-config.git ) 2 times, one without depth and one with depth=1.例如,请参见下图,其中我克隆了同一个存储库 ( https://github.com/spring-cloud/spring-cloud-config.git ) 2 次,一次没有深度,一次深度为 1。 In first case, the local repository size is 40 MB and with depth the local repository size is mere 3.4 MB.在第一种情况下,本地存储库大小为 40 MB,而对于深度,本地存储库大小仅为 3.4 MB。

浅克隆

I would recommend to check https://issues.jenkins-ci.org/browse/JENKINS-43878 for better understanding.我建议检查https://issues.jenkins-ci.org/browse/JENKINS-43878以获得更好的理解。 The reporter of this ticket compares the duration of clone+checkout process in 3 cases: non-shallow clone with git command, shallow clone with pipeline and shallow clone(depth=1) with git command, and the ticket reporter complains that case #2 lasts much longer than case #3.这张票的报告者比较了3种情况下clone+checkout过程的持续时间:使用git命令的非浅克隆、使用管道的浅克隆和使用git命令的浅克隆(深度=1),并且票报告者抱怨的是这种情况#2持续时间比案例#3 长得多。

I exercised with the repo https://github.com/tesseract-ocr/tessdata (~5 GB) and I could not reproduce the duration difference.我使用 repo https://github.com/tesseract-ocr/tessdata (~5 GB) 进行了练习,但无法重现持续时间差异。 But I observed the big size difference.但我观察到了很大的尺寸差异。 These are my measurements:这些是我的测量结果:

  1. Non-shallow clone with pipeline: 8 min, total size 4615 MB, "fetch size" 3256 MB.带管道的非浅层克隆:8 分钟,总大小 4615 MB,“提取大小”3256 MB。
  2. Non-shallow clone with git command: 8 min, total size 4615 MB.使用 git 命令的非浅层克隆:8 分钟,总大小 4615 MB。
  3. Shallow clone with pipeline: 4-5 min, total size 3121 MB, "fetch size" 1762 MB带管道的浅克隆:4-5 分钟,总大小 3121 MB,“提取大小”1762 MB
  4. Shallow clone(depth=1) with git command: 4-5 min, total size 1995 MB.使用 git 命令进行浅克隆(深度=1):4-5 分钟,总大小 1995 MB。

(the "fetch" size in my comparison is the size of the directory which I measured with "du -ms" at the moment after "git fetch" and before "git checkout" when it was done with the help of Jenkins pipeline) (我比较中的“fetch”大小是我在“git fetch”之后和“git checkout”之前用“du -ms”测量的目录大小,当它在Jenkins管道的帮助下完成时)

If you compare cases 2 and 3 you will see that for shallow clone the approach "fetch+checkout" leads to more disk space occupation than for the normal "clone".如果比较案例 2 和案例 3,您会发现对于浅克隆,“fetch+checkout”方法比普通“clone”占用更多的磁盘空间。

The pipeline maintainers agreed with this fact, but closed the ticket with "Won't fix", because they don't want to change the way of working from "fetch+checkout" to "clone" for the plugin due to other reasons.管道维护人员同意这一事实,但以“不会修复”关闭了票证,因为他们不想由于其他原因将插件的工作方式从“获取+结帐”更改为“克隆”。

This is exactly answer to your question why don't you see big difference between shallow and full clone for Jenkins pipeline: because Jenkins pipeline uses "fetch+checkout" approach which in case of --depth works differently than "clone" and downloads more data than "clone".这正是您问题的答案,为什么您看不到 Jenkins 管道的浅层克隆和完整克隆之间的巨大差异:因为 Jenkins 管道使用“获取+结帐”方法,在 --depth 的情况下,该方法与“克隆”的工作方式不同并且下载更多数据比“克隆”。

If you need a normal "clone --depth" it should be run as a shell command from the pipeline script.如果您需要一个普通的“clone --depth”,它应该作为来自管道脚本的 shell 命令运行。 On my opinion it is a disadvantage of Jenkins pipeline.在我看来,这是 Jenkins 管道的一个缺点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM