【问题标题】:Jenkinsfile declarative script git plugin: how to set shallow clone and depth attributesJenkinsfile 声明性脚本 git 插件:如何设置浅克隆和深度属性
【发布时间】:2021-11-22 15:18:24
【问题描述】:

我在 Jenkinsfile 中有一个声明性管道,我将在其中添加浅克隆选项,深度 = 1,超时 = 30 在 git 插件中。目前我的设置是:

            git(
                credentialsId: 'MY_GIT_CREDENTIALS', 
                branch: "${params.BRANCH}", 
                url: "${env.BBSCM}"
            )

有人可以帮我在语句中添加三个所需的参数吗?

【问题讨论】:

    标签: plugins jenkins-pipeline declarative


    【解决方案1】:

    要启用这些额外的自定义选项,您需要使用完整且推荐的 SCM Step checkout methodGitSCM 类。查阅文档后,我们看到您当前和所需参数的语法和用法如下所示:

    checkout([
      $class: 'GitSCM',
      branches: [[name: "*/${params.BRANCH}"]],
      extensions: [[
        $class: 'CloneOption',
        shallow: true,
        depth:   1,
        timeout: 30
      ]],
      userRemoteConfigs: [[
        url:           params.SCM_URL,
        credentialsId: 'MY_GIT_CREDENTIALS'
      ]]
    ])
    

    如果您是 Jenkins Pipeline 的新手,并且这种语法和用法看起来令人生畏,请注意,将来您还可以使用 Pipeline Syntax Snippet Generator 寻求帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-17
      • 1970-01-01
      • 2013-10-11
      • 2013-04-28
      • 1970-01-01
      • 2017-04-25
      • 2020-03-04
      相关资源
      最近更新 更多