如何在 Jenkins Git 插件中指定作业 DSL 校验超时?
How to specify Job DSL checkout timeout in Jenkins Git plugin?
可以使用以下方式指定克隆超时:
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...
}
...
}
...
}
...
使用工作流插件做这样的事情怎么样?
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CheckoutOption', timeout: 100]], submoduleCfg: [], userRemoteConfigs: [[]]])
经过一些实验,我找到了如下所示的解决方案。
回顾
可以通过 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
}
}
}
...
}
...
}
...
由于 CheckoutOption 对我不起作用
,我不得不像这样更改管道
扩展:[[$class:'CloneOption',超时:120]]
完整结帐代码
checkout([$class: 'GitSCM', branches: [[name: '*/master']],
extensions: [[$class: 'CloneOption', timeout: 120]], gitTool: 'Default',
userRemoteConfigs: [[credentialsId: key, url: repo]]
])
以下结帐配置在 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"]
]])
}
}
添加此扩展对我有用。
extensions: [[$class: 'CloneOption', timeout: 60]]
可以使用以下方式指定克隆超时:
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...
}
...
}
...
}
...
使用工作流插件做这样的事情怎么样?
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CheckoutOption', timeout: 100]], submoduleCfg: [], userRemoteConfigs: [[]]])
经过一些实验,我找到了如下所示的解决方案。
回顾
可以通过 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
}
}
}
...
}
...
}
...
由于 CheckoutOption 对我不起作用
,我不得不像这样更改管道扩展:[[$class:'CloneOption',超时:120]]
完整结帐代码
checkout([$class: 'GitSCM', branches: [[name: '*/master']],
extensions: [[$class: 'CloneOption', timeout: 120]], gitTool: 'Default',
userRemoteConfigs: [[credentialsId: key, url: repo]]
])
以下结帐配置在 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"]
]])
}
}
添加此扩展对我有用。
extensions: [[$class: 'CloneOption', timeout: 60]]