Jenkins :如何在 Jenkins 声明式管道中实现并行动态阶段



我正在研究声明式管道。我正在尝试实现动态阶段,该阶段应与定义的代理并行分布阶段。当我探索时,我学会了如何实现动态顺序阶段。下面是我的示例代码。

我现在的问题是,如何与我拥有的代理实现并行阶段。例如,如果我有 3 个代理,则所有 5 个阶段都应在代理并行中并行运行。我尝试使用并行测试,但不起作用。请帮助我进一步改进!

def learn
pipeline {
agent none
stages {
stage('Dynamic Stages') {
steps {
script {
learn = ["1", "2", "3", "4", "5"]
for(int i=0; i < list.size(); i++) {
stage(list[i]){
echo "value: $i"
}
}
}
}
}
}
}

以下内容应并行运行所有阶段。Jenkins 只会采用任何可用的节点。

def learn
pipeline {
agent none
stages {
stage('Dynamic Stages') {
steps {
script {
learn = ["1", "2", "3", "4", "5"]
def builders = [:]
for(i in learn) {
def value = i // Need to bind the label variable before the closure - can't do 'for (i in learn)
builders[i] = {
node {
echo "value: $i"
}
}
}
parallel builders
}
}
}
}
}

最新更新