动态创建的 Jenkins 管道脚本
Jenkins pipeline script created dynamically
我正在使用 jenkins 管道项目。在脚本中,我想以动态方式编写 parallel 块,因为节点数可以改变。例如,来自:
parallel(
node1: {
node(){
stage1()
stage2()
...
}
},
node2: {
node(){
stage1()
stage2()
...
}
},
...
)
像这样
for (int i = 0; i < $NODE_NUMBER; i++) {
"node${i}": {
node (’namenode-' + ${i}) {
something()
}
}
但是这种方式行不通,Groovy/Jenkins 对这种语法不满意。有人可以建议更好的方法吗?
可以先定义节点映射如branches
,然后执行parallel branches
。
def numNodes = 4
def branches = [:]
for(int i = 0; i < numNodes; i++) {
branches["node${i}"] = {
node("namenode-${i}") {
something()
}
}
}
parallel branches
我正在使用 jenkins 管道项目。在脚本中,我想以动态方式编写 parallel 块,因为节点数可以改变。例如,来自:
parallel(
node1: {
node(){
stage1()
stage2()
...
}
},
node2: {
node(){
stage1()
stage2()
...
}
},
...
)
像这样
for (int i = 0; i < $NODE_NUMBER; i++) {
"node${i}": {
node (’namenode-' + ${i}) {
something()
}
}
但是这种方式行不通,Groovy/Jenkins 对这种语法不满意。有人可以建议更好的方法吗?
可以先定义节点映射如branches
,然后执行parallel branches
。
def numNodes = 4
def branches = [:]
for(int i = 0; i < numNodes; i++) {
branches["node${i}"] = {
node("namenode-${i}") {
something()
}
}
}
parallel branches