所以我有一个Jenkinsfile
像这样:
properties([
[$class: 'BuildDiscarderProperty',
strategy: [$class: 'LogRotator',
numToKeepStr: '10',
artifactNumToKeepStr: '15']]
])
List<String> buildFlavours = ['ubuntu', 'macosx']
List<BuildStep> modulesGroups = [
new BuildStep('UnitTestGroup1'),
new BuildStep('UnitTestGroup2')
]
println "*** outside loop, buildFlavours.size() = ${buildFlavours.size()}"
buildFlavours.each { flavour ->
println "*** inside loop, flavour = ${flavour}"
println "*** outside loop, modulesGroups.size() = ${modulesGroups.size()}"
modulesGroups.each { group ->
// Doesn't work, silently terminates the pipeline with no error!
println "*** inside loop, group = ${group}"
// Somehow this works:
// String groupCopy = group.toString()
// println "*** inside loop, group = ${groupCopy}"
}
}
class BuildStep {
private String displayName
BuildStep(String displayName) {
this.displayName = displayName
}
@Override
String toString() {
return displayName
}
}
运行它时,得到以下输出:
[Pipeline] properties
[Pipeline] echo
*** outside loop, buildFlavours.size() = 2
[Pipeline] echo
*** inside loop, flavour = ubuntu
[Pipeline] echo
*** outside loop, modulesGroups.size() = 2
[Pipeline] echo
*** inside loop, flavour = macosx
[Pipeline] echo
*** outside loop, modulesGroups.size() = 2
[Pipeline] End of Pipeline
看起来好像不执行循环的内容,既不打印消息也不引发错误,这是怎么回事?
我最好的领导者是詹金斯(Jenkins)正在使用Groovy CPS之类的东西,也许出于某种原因它可能正在加紧重写代码。
到目前为止的调查:
Throwable
-如果我尝试抓住一个,那就什么也没抓住。toString()
对象时,以某种方式起作用起作用,并且循环内的消息确实被打印了,但是我没有弄清楚为什么呢?BuildStep
类可序列化或更改其名称不会产生任何影响。