温馨提示:本文翻译自stackoverflow.com,查看原文请点击:jenkins pipeline - git clone without history using SCM
git jenkins-pipeline

jenkins pipeline - git无历史记录使用SCM

发布于 2020-03-27 10:16:51

我们的项目非常庞大,我们希望避免克隆所有git历史记录。

Jenkins 是否可以git clone通过depth=1使用checkout scm

SCM如果可能,我找不到任何有关如何配置或如何传递参数的文档

补充:
找到文档

https://jenkins.io/doc/pipeline/steps/workflow-scm-step/#code-checkout-code-general-scm

类型:int
depth(可选)
设置浅克隆深度,以便git仅下载项目的最新历史记录,从而在您只想访问存储库的最新版本时节省时间和磁盘空间。

但尚不清楚如何将其传递给 checkout scm

查看更多

查看更多

提问者
marco
被浏览
393
Szymon Stepniak 2019-07-03 21:12

如果您使用脚本化管道,则可以自定义checkout scm使其大致如下所示:

node {
    checkout([
        $class: 'GitSCM',
        branches: scm.branches,
        doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
        extensions: scm.extensions,
        userRemoteConfigs: scm.userRemoteConfigs,
        depth: 1
    ])
}

如果您使用声明性管道,则需要转到管道作业配置,并且在“ 行为”部分中,需要添加Git-> Advanced克隆行为,并标记Shallow clone并将Shallow clone depth设置1

在此处输入图片说明