本文介绍了jenkins管道:如何在代理列表上并行执行功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一堆服务于标签rhel6
,rhel7
的节点.
I have a bunch of nodes serving labels rhel6
, rhel7
.
如何在rhel6
的任意2个节点和rhel7
-的任意3个节点上并行执行myFunc()
?
How do I execute myFunc()
on any 2 nodes of rhel6
and any 3 nodes rhel7
- in parallel?
def slaveList = ['rhel6', 'rhel6', 'rhel7', 'rhel7', 'rhel7']
def stageFunc (String slaveLabel) {
return {
// Run this stage on any available node serving slaveLabel
agent { label "${slaveLabel}" } // Error shown here.
stage {
myFunc()
}
}
}
pipeline {
agent any
stages {
stage('Start') {
steps {
script {
def stageMap = [:]
def i = 0
slaveList.each { s ->
stageMap[i] = stageFunc(s)
i++
}
parallel stageMap
}
}
}
}
}
显示的错误:java.lang.NoSuchMethodError: No such DSL method 'agent' found among steps [archive, ...
推荐答案
我尚未对此进行测试,但应该可以.
I haven't tested this yet, but it should work.
def slaveList = ['rhel6', 'rhel6', 'rhel7', 'rhel7', 'rhel7']
def stageFunc (stage_name, slaveLabel) {
return {
// Run this stage on any available node serving slaveLabel
stage(stage_name){
node(slaveLabel) {
myFunc()
}
}
}
}
pipeline {
agent any
stages {
stage('Start') {
steps {
script {
def stageMap = [:]
def i = 0
slaveList.each { s ->
stageMap[i] = stageFunc("Stage-${i}", s)
i++
}
parallel stageMap
}
}
}
}
}
这篇关于jenkins管道:如何在代理列表上并行执行功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!