Nicholas Smith Nicholas Smith - 8 months ago 73
Groovy Question

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){ = 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 ::::: ${}"
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


The messages "Running: Print Message" and "Running: End of Workflow" indicate that you are using the new workflow plugin: This plugin currently has a bug causing at least some Groovy iterations involving a closure to be aborted after one iteration: