我这样设置 Jenkins 工作管道
properties()
properties([
[$class: "jenkins.model.BuildDiscarderProperty", strategy: [$class: "LogRotator", numToKeepStr: "50", artifactNumToKeepStr: "20"]],
parameters([
string(name: "BUILD_NODE", defaultValue: "linux", description: "Build node to use."),
choiceParam(name: "DEBUG_LEVEL", choices: ["0", "1", "2", "3"], description: "Debugger verbosity.")
])
])
我希望能够有选择地禁用并发构建,因此作为测试代码我尝试了这个
List propsList = [
[$class: "jenkins.model.BuildDiscarderProperty", strategy: [$class: "LogRotator", numToKeepStr: "50", artifactNumToKeepStr: "20"]],
parameters([
string(name: "BUILD_NODE", defaultValue: "linux", description: "Build node to use."),
choiceParam(name: "DEBUG_LEVEL", choices: ["0", "1", "2", "3"], description: "Debugger verbosity.")
])
]
if (env.DONT_WANT_CONCURRENT_BUILDS.toBoolean()) {
JobProperty jp = disableConcurrentBuilds()
}
properties(propsList)
但是当我运行作业时,我得到以下信息
hudson.remoting.ProxyException: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '@disableConcurrentBuilds()' with class 'org.jenkinsci.plugins.workflow.cps.UninstantiatedDescribableWithInterpolation' to class 'hudson.model.JobProperty'
正确的做法是什么?谢谢!
这在概念上是错误的。 “禁用并发构建”属性是作业的属性。虽然 Jenkins 允许您在作业运行期间动态设置这些属性,但这个特定属性在那里没有意义。如果您的运行想要将其设置为 true,但已经有另一个并发作业正在运行,该怎么办?詹金斯应该终止这份工作吗?
想想是什么让你的工作不可重入。使用信号量隔离该部分。