【问题标题】:How to specify Job DSL checkout timeout in Jenkins Git plugin?如何在 Jenkins Git 插件中指定 Job DSL 签出超时?
【发布时间】:2016-06-24 08:25:08
【问题描述】:

可以使用以下方式指定克隆超时:

git {
    ...
    cloneTimeout(60)
}

其中 60 是超时是分钟。我读到也可以指定结帐超时,但我找不到详细信息。 checkoutTimeout(...)timeout(...) 都会报错。​​

编辑

我可以通过 Jenkins GUI 设置结帐超时时间(Configuration --> SCM --> Git --> Additional Behaviors --> Advanced Checkout Behaviors --> Timeout)。我想在为 Jenkins 生成 Docker 配置的 Groovy 脚本中做同样的事情:

...
public class DockerJob {
...
    multiscm {
        git {
            remote {
                url(...)
                branch(...)
                ...
            }
            shallowClone()
            cloneTimeout(60)
            // Add "checkout timeout" here...
        }
        ...
    }
    ...
}
...

【问题讨论】:

  • 您是否在询问如何通过 Jenkins UI 在作业配置中执行此操作?

标签: jenkins jenkins-plugins jenkins-job-dsl


【解决方案1】:

使用工作流插件并做这样的事情怎么样?

checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CheckoutOption', timeout: 100]], submoduleCfg: [], userRemoteConfigs: [[]]])

【讨论】:

  • 为简单起见,我想要一个类似于克隆超时的解决方案(用于结帐超时)。
【解决方案2】:

经过一些实验,我找到了如下所示的解决方案。

回顾

结帐超时可以通过 Jenkins GUI 设置(Configuration --> SCM --> Git --> Additional Behaviors --> Advanced Checkout Behaviors --> Timeout)。我想在为 Jenkins 生成 Docker 配置的 Groovy 脚本中做同样的事情。该脚本已设置克隆超时。

...
public class DockerJob {
...
    multiscm {
        git {
            remote {
                url(...)
                branch(...)
                ...
            }
            shallowClone()
            cloneTimeout(60)
            // Add "checkout timeout" here...
        }
        ...
    }
    ...
}
...

显而易见的

...
// "Checkout timeout"
checkoutTimeout(60)
...

没用。一般设置超时

...
// "Checkout timeout"
timeout(60)
...

也没有工作。然后在一个网页上发表评论导致:

...
// "Checkout timeout"
extensions {
    checkoutOptions {
        timeout(60)
    }
}
...

那也没用。终于……

解决方案

...
public class DockerJob {
...
    multiscm {
        git {
            remote {
                url(...)
                branch(...)
                ...
            }
            shallowClone()
            cloneTimeout(60)
            // "Checkout timeout"
            configure { node ->
                node / 'extensions' << 'hudson.plugins.git.extensions.impl.CheckoutOption' {
                    timeout 60
                }
            }
        }
        ...
    }
    ...
}
...

【讨论】:

    【解决方案3】:

    我不得不像这样使用管道进行更改,因为 CheckoutOption 对我不起作用

    扩展:[[$class: 'CloneOption', timeout: 120]]

    完整的结帐代码

    checkout([$class: 'GitSCM', branches: [[name: '*/master']],
                extensions: [[$class: 'CloneOption', timeout: 120]], gitTool: 'Default', 
                userRemoteConfigs: [[credentialsId: key, url: repo]]
            ])
    

    【讨论】:

      【解决方案4】:

      在 jenkins 管道脚本中执行结帐配置非常适合我。我们使用 stash1 就像 github 作为内部 git 服务器。用你自己的替换它。

      stage('Checkout') {
                  steps {
                      echo "Running checkout stage"
                      checkout([$class: 'GitSCM', branches: [
                          [name: "*/${params.branch}"]
                      ], doGenerateSubmoduleConfigurations: false, extensions: [
                          [$class: 'CleanCheckout'], [$class: 'CloneOption', timeout: 30, shallow: true]
                      ], submoduleCfg: [], userRemoteConfigs: [
                          [credentialsId: 'ink_bot', url: "ssh://git@stash1.XYZ.com:7999/int_sparktp/${params.repo}.git"]
                      ]])
                  }
              }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-10-20
        • 1970-01-01
        • 1970-01-01
        • 2016-02-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多