10

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

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...
        }
        ...
    }
    ...
}
...
4

4 回答 4

15

我不得不像这样用管道改变它,因为CheckoutOption不适合我

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

完整的结帐代码

checkout([$class: 'GitSCM', branches: [[name: '*/master']],
            extensions: [[$class: 'CloneOption', timeout: 120]], gitTool: 'Default', 
            userRemoteConfigs: [[credentialsId: key, url: repo]]
        ])
于 2017-08-30T14:36:10.223 回答
8

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

回顾

结帐超时可以通过 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
                }
            }
        }
        ...
    }
    ...
}
...
于 2016-04-03T10:23:03.410 回答
2

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

checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CheckoutOption', timeout: 100]], submoduleCfg: [], userRemoteConfigs: [[]]])
于 2016-03-10T09:31:09.130 回答
0

在 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"]
                ]])
            }
        }
于 2019-12-11T09:33:11.550 回答