为什么詹金斯不运行此循环的内容?

时间:2019-05-20 02:14:24

标签: jenkins groovy jenkins-pipeline

所以我有一个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之类的东西,也许出于某种原因它可能正在加紧重写代码。

到目前为止的调查:

  1. 它不会抛出任何类型的Throwable-如果我尝试抓住一个,那就什么也没抓住。
  2. 当我首先将循环内的println更改为toString()对象时,以某种方式起作用起作用,并且循环内的消息确实被打印了,但是我没有弄清楚为什么呢?
  3. 使BuildStep类可序列化或更改其名称不会产生任何影响。
  4. 暂时filed a ticket,因为至少我认为错误的错误报告可以解决。

0 个答案:

没有答案