我正在尝试并行调用多次函数,但实际上并不知道将调用多少次,这取决于列表中的值。 代码示例:
def buildJob(jobName) {
echo "${jobName} will be built." //testing output before really building jobs
}
node {
projects = ['project1-dev', 'project2-dev', 'project1-qa', 'project2-qa', 'project1-pp', 'project2-pp']
stage ('Build') {
for (project in projects) {
parallel(
"${project}": buildJob(project), failFast: true
)
}
}
}
我希望代码生成如下内容:
stage ('Build') {
parallel (
'project1-dev': { buildJob('project1-dev') },
'project1-qa': { buildJob('project1-qa') },
'project1-pp': { buildJob('project1-pp') },
...
)
}
但是我真的不理解如何传递参数buildJob(project),我尝试了许多不同的方法,有时会遇到failFast错误,有时会出现项目名称错误,有时无法完全识别地图。 我什至制作了一个地图并向其中动态添加了值,但是我认为这过于复杂了,我只想多次调用该函数,并且不等待结果,只是等待每个调用完成。
有人可以帮忙吗? 非常感谢! 最好的问候
答案 0 :(得分:0)
经过数小时的战斗,我像这样解决了它:
includePaths
答案 1 :(得分:0)
使用each
代替for
解决了该问题:
def buildJob(jobName){
echo "${jobName} will be built."
}
node {
map = [:]
projects = ['project1-dev', 'project2-dev', 'project1-qa', 'project2-qa', 'project1-pp', 'project2-pp']
stage ('Build') {
projects.each() {
map[it] = { buildJob(it) }
}
parallel map
}
}