您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Jenkins中的数组简单并行执行

Jenkins中的数组简单并行执行

这是一个非常令人讨厌的限制,但是当前您不能.each在管道脚本中使用(如此处记录:https : //issues.jenkins-ci.org/browse/JENKINS-26481)

您需要做一个实际的循环,例如

String[] arr = [ "one","two","three",'four','five' ]
echo "Running commands: ${arr}"
int top = arr.size()
echo "top is ${top}"
for (it in arr) {
    echo "${it}"
}

如果实际需要并行执行,则代码将更像:

String[] arr = [ "one","two","three",'four','five' ]
echo "Running commands: ${arr}"
int top = arr.size()
echo "top is ${top}"
def stepsForParallel = [:]

for (int i = 0; i < arr.size(); i++) {
    def it = arr[i]
    def stepName = "running ${it}"
    stepsForParallel[stepName] = { ->           
        echo "${it}"
    }
}

parallel stepsForParallel

链接到的另一个stackoverflow使用Build Flow插件,它是您正在使用的Pipeline插件的前身。这就是为什么相同的代码不起作用的原因。

在现代詹金斯(在2.150.1中进行测试)上面列出的原始错误是固定的,并且.each可以工作。您可以为并行执行执行以下操作:

String[] arr = [ "one","two","three",'four','five' ]

def stepsForParallel = [:]
arr.each {
    def stepName = "running ${it}"
    stepsForParallel[stepName] = { ->           
        echo "${it}"
    }
}
parallel stepsForParallel
其他 2022/1/1 18:14:45 有445人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶