7

我正在使用 Jenkins 文件来构建管道。我正在尝试使用 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']])

并且当管道正在执行时,它正在被翻译成这个

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

这会在我的 Jenkins 服务器上克隆整个存储库。我只想获得我的 repo 的浅表副本,以便我可以将我的 Jenkins 服务器从空间紧缩中拯救出来。请在这里帮忙。

我正在使用:詹金斯版本:2.58,

插件:

流水线 SCM 步骤:2.4

吉特:3.3.0

4

2 回答 2

6

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.

For more information please follow this link: 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. In first case, the local repository size is 40 MB and with depth the local repository size is mere 3.4 MB.

shallow clone

于 2019-06-10T14:30:30.863 回答
3

我建议检查https://issues.jenkins-ci.org/browse/JENKINS-43878以获得更好的理解。这张票的记者对比了3种情况下clone+checkout过程的持续时间:用git命令进行非浅克隆,用管道进行浅克隆,用git命令进行浅克隆(depth=1),票报告人抱怨案例#2持续时间比案例 #3 长得多。

我使用 repo https://github.com/tesseract-ocr/tessdata (~5 GB) 进行了锻炼,但我无法重现持续时间的差异。但我观察到了巨大的尺寸差异。这些是我的测量结果:

  1. 带管道的完整克隆:8 分钟,总大小 4615 MB,“获取大小”3256 MB。
  2. 使用“git clone”的完整克隆:8 分钟,总大小 4615 MB。
  3. 使用管道的浅克隆(深度=1):4-5 分钟,总大小 3121 MB,“获取大小”1762 MB
  4. 带有“git clone”的浅克隆(深度=1):4-5 分钟,总大小 1995 MB。

(我比较中的“fetch”大小是我在“git fetch”之后和“git checkout”之前在 Jenkins 管道的帮助下使用“du -ms”测量的目录大小)

如果您比较案例 3 和案例 4,您会发现对于浅层克隆,管道(即“提取+签出”)方法会导致比普通“克隆”更多的磁盘空间占用。

管道维护者同意这一事实,但以“Won't fix”关闭票证,因为他们不想由于其他原因将插件的工作方式从“fetch+checkout”更改为“clone”。

这正是您的问题的答案,为什么您看不到 Jenkins 管道的浅层克隆和完整克隆之间的巨大差异:因为 Jenkins 管道使用“fetch+checkout”方法,在 --depth 的情况下,它的工作方式与“clone”不同并且下载更多数据比“克隆”。

如果您需要普通的“克隆 --depth”,它应该作为管道脚本中的 shell 命令运行。在我看来,这是 Jenkins 管道的一个缺点。

于 2019-11-21T13:47:51.893 回答