Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
709 views
in Technique[技术] by (71.8m points)

jenkins - Groovy .each only iterates one time

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

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";
    }
};

This is the result of the run. The array shows 4 elements, but the code inside the .each black only executes once.

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: End of Workflow
Finished: SUCCESS

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...