14

スクリプトは、'modules' 配列のすべての値を反復処理していません。

class Module {
    public String name = '';
    public Boolean isCustom = false;
    public Module(String name, Boolean custom){
        this.name = name;
        this.isCustom = custom;
    }
}

//creates array from the ext_module env var
modules = [];
EXT_MODULE.split(',').each { 
    modules.add(new Module(it, false));
}


println modules;
modules.each {  
    println "MODULE NAME ::::: ${it.name}"
    if(it.isCustom)
    {
        println "install custom";
    } else {
        println "install non custom";
    }
};

これが実行結果です。配列は 4 つの要素を示していますが、.each 黒内のコードは 1 回しか実行されません。

Running: Print Message [Module@71f09325, Module@e1ddb41, Module@7069a674, Module@1f68f952]
Running: Print Message MODULE NAME ::::: puppetlabs-ntp
Running: Print Message install non custom
Running: E​​nd of Workflow
Finished: SUCCESS

4

3 に答える 3

10

「Running: Print Message」および「Running: E​​nd of Workflow」というメッセージは、新しいワークフロー プラグインを使用していることを示します: https://wiki.jenkins-ci.org/display/JENKINS/Workflow+Plugin。現在、このプラグインにはバグがあり、クロージャーを含む少なくともいくつかの Groovy 反復が 1 回の反復後に中止されます: https://issues.jenkins-ci.org/browse/JENKINS-26481

于 2015-01-21T08:46:53.120 に答える
4

回避策は、古い学校の for loop を単純に使用すること(code below)です。また、NonCPS も別の回避策です。この件に関して未解決の問題があります。ここを参照してください: https://issues.jenkins-ci.org/browse/JENKINS-26481

更新、2016 年 10 月 24 日

/** *古い学校の for ループを使用して、環境変数をログにダンプします。 */

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;
于 2016-03-04T20:23:06.307 に答える