首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jenkins管道:如何并行执行代理列表上的函数?

jenkins管道:如何并行执行代理列表上的函数?
EN

Stack Overflow用户
提问于 2019-04-09 10:09:48
回答 1查看 1.4K关注 0票数 0

我有一堆节点为标签rhel6rhel7提供服务。

如何在任意两个myFunc()节点上并行执行rhel6和任意3个节点rhel7

代码语言:javascript
复制
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, ...

EN

回答 1

Stack Overflow用户

发布于 2019-05-07 13:16:40

我还没测试过这个,但应该能用。

代码语言:javascript
复制
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
                }
            }
        }        
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55590295

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档