Groovy .each only iterates one time

前端 未结 3 1365
攒了一身酷
攒了一身酷 2020-12-09 18:08

The script is not iterating through all the values of the \'modules\' array.

class Module {
    public String name =         


        
相关标签:
3条回答
  • 2020-12-09 18:50

    The workaround is to simply use an old school for loop (code below). Also, NonCPS is another workaround. There is an open issue for this matter. See here: https://issues.jenkins-ci.org/browse/JENKINS-26481

    Update, Oct 24th, 2016

    /** * Dumps environment varibles to the log, using an old school for loop. */

    import com.cloudbees.groovy.cps.NonCPS
    
    def version = '1.0'
    
    @NonCPS
    def dumpEnvVars() {
      def str = "Dumping build environment variables...\n"
      for (Map.Entry<String, String> entry : currentBuild.build().environment) {
        str += "    ${entry.key} = ${entry.value}\n"
      }
      echo str
    }
    
    return this;
    
    0 讨论(0)
  • 2020-12-09 18:53

    The messages "Running: Print Message" and "Running: End of Workflow" indicate that you are using the new workflow plugin: https://wiki.jenkins-ci.org/display/JENKINS/Workflow+Plugin. This plugin currently has a bug causing at least some Groovy iterations involving a closure to be aborted after one iteration: https://issues.jenkins-ci.org/browse/JENKINS-26481

    0 讨论(0)
  • 2020-12-09 18:58

    As of yesterday, the new Pipeline plugin was delivered in version 2.0 and correct this problem.

    .each closures now work, but .collect still only iterate once.

    0 讨论(0)
提交回复
热议问题