jenkins管道:如何在代理列表上并行执行功能? [英] jenkins pipeline : How to execute a function on a list of agents in parallel?

查看:100
本文介绍了jenkins管道:如何在代理列表上并行执行功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆服务于标签rhel6rhel7的节点.

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管道:如何在代理列表上并行执行功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆