如何并行执行从另一个Groovy文件导入的列表? [英] How to parelelly execute a list imported from another Groovy file?
本文介绍了如何并行执行从另一个Groovy文件导入的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从另一个常规文件导入列表,并利用它来遍历内容:
I am importing a list from another groovy file and Utilizing it to iterate through the content:
第一.groovy
def getContent() {
def content = ["one", "two"]
return content
}
return this;
并这样称呼它:
def first = load 'First.groovy'
def content = first.getContent()
stage("Build services") {
parallel content { CONTENT_NAME ->
[CONTENT_NAME, {
//iterate through each job
try {
some code;
}
catch (err) {
echo err.toString()
currentBuild.result = 'FAILURE'
throw err
}
}]
}
但是我遇到了错误-
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.call() is applicable for argument types: (org.jenkinsci.plugins.workflow.cps.CpsClosure2) values:
[org.jenkinsci.plugins.workflow.cps.CpsClosure2@23856748]
Possible solutions: tail(), tail(), wait(), last(), last(), any()
解决这个问题有什么线索吗?
Any clue on resolving this?
推荐答案
parallel:并行执行将分支名称映射到关闭
parallel: Execute in parallel Takes a map from branch names to closures
您需要先创建一个地图,然后根据 parallel .您的 content
只是一个列表.
You need to create a map first and then execute it per parallel. Your content
is only a List.
我将建议如何构建任务的另一种方法:
I would suggest a different approach on how to build the tasks:
def parallelTasks = [:]
for (element in content) {
parallelTasks["${element}"] = {
echo "${element}"
}
}
parallel parallelTasks
这篇关于如何并行执行从另一个Groovy文件导入的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文