且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jenkins管道:如何在代理列表上并行执行功能?

更新时间:2021-08-08 02:34:50

我尚未对此进行测试,但应该可以.

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
                }
            }
        }        
    }
}