Declarative pipeline - How can i use multiple agents within a stage executing in a sequence ?

33 views
Skip to first unread message

ishan jain

unread,
May 3, 2017, 10:58:57 AM5/3/17
to Jenkins Users
I am using declarative pipeline and in some of my stages, i need to use multiple agents while still ensuring the steps are executed in sequence (not parallel). I don't find a nice way to use multiple agents (maybe multiple steps) within a stage.

something like:

pipeline {
   agent none
         
     stages {
       
               stage ('prepare') {
                    agent any
                     
                        steps {
                        script {
                                       echo "somrthing"
                               }
                      }
              }
              stage('Build') {
           
                   agent { label 'master'  }
                     
                        steps {
                        echo 'on master'
                       }
                     
                        agent { label 'slave1'}
               
                        steps {
                        echo 'on slave'
                }
                     
        }
             
    }
}


Since this is not supported, i am forced to use a less elegant way:


pipeline {
   agent none
         
     stages {
       
               stage ('prepare') {
                    agent any
                     
                        steps {
                        script {
                                       echo "somrthing"
                               }
                      }
              }
              stage('Build') {
           
                   agent { label 'master'  }
                     
                        steps {
                        echo 'on master'
                               executeOnSlave()
                       }
                     
        }
             
    }
}
def executeOnSlave() {
   node ('slave1') {
              echo 'on slave'
}
}



Reply all
Reply to author
Forward
0 new messages