0

I have a bunch of nodes serving labels rhel6, rhel7.

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

Error shown: java.lang.NoSuchMethodError: No such DSL method 'agent' found among steps [archive, ...

1 Answers1

0

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
                }
            }
        }        
    }
}
Tai Ly
  • 341
  • 1
  • 2
  • 10