Jenkins 闭包中的Groovy函数调用

Jenkins 闭包中的Groovy函数调用,jenkins,groovy,jenkins-workflow,jenkins-pipeline,Jenkins,Groovy,Jenkins Workflow,Jenkins Pipeline,在Groovy中如何在闭包中进行函数调用?当前正在尝试此操作,但使用最后一个数组元素的值会导致所有迭代: def branches = [:] for (int i = 0; i < data.steps.size(); i++) { branches["${data.steps.get(i).name}"] = { myFunc(data.steps.get(i)) } } parallel branches def分支=[:] 对于(int i=0;i

在Groovy中如何在闭包中进行函数调用?当前正在尝试此操作,但使用最后一个数组元素的值会导致所有迭代:

def branches = [:]
for (int i = 0; i < data.steps.size(); i++) {
    branches["${data.steps.get(i).name}"] = {
        myFunc(data.steps.get(i))
    }
}
parallel branches
def分支=[:]
对于(int i=0;i
这是一个

这应该起作用:

def branches = data.steps.collectEntries { step ->
    [step.name, { myFunc(step) }]
}
parallel branches

def branchs=data.steps.inject([:]){map,step->

map不幸的是,我无法测试它,因为Jenkins在collectEntries方法上给出了一个脚本安全错误,我无法将其列入白名单,但我不怀疑它是否有效。该链接非常方便,谢谢!添加了一个使用
inject
def branches = data.steps.inject([:]) { map, step ->
    map << [(step.name): { myFunc(step) }]
}