Groovy .each 只迭代一次 [英] Groovy .each only iterates one time

查看:24
本文介绍了Groovy .each 只迭代一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

脚本没有遍​​历 'modules' 数组的所有值.

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

这是运行的结果.该数组显示 4 个元素,但 .each black 中的代码仅执行一次.

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

运行:打印消息[模块@71f09325、模块@e1ddb41、模块@7069a674、模块@1f68f952]
运行:打印消息模块名称 ::::: puppetlabs-ntp
运行:打印消息安装非自定义
运行:工作流结束
完成:成功

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

推荐答案

消息正在运行:打印消息"和正在运行:工作流结束"表明您正在使用新的工作流插件:https://wiki.jenkins-ci.org/display/JENKINS/Workflow+Plugin.这个插件目前有一个错误,导致至少一些涉及闭包的 Groovy 迭代在一次迭代后被中止:https://issues.jenkins-ci.org/browse/JENKINS-26481

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

这篇关于Groovy .each 只迭代一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆