Can I Define Multiple Agent Labels In A Declarative Jenkins Pipeline?


Answer :

You can see the 'Pipeline-syntax' help within your Jenkins installation and see the sample step "node" reference.

You can use exprA||exprB:

node('small||medium') {     // some block } 

This syntax appears to work for me:

agent { label 'linux && java' } 

EDIT: I misunderstood the question. This answer is only if you know which specific agent you want to run for each stage.

If you need multiple agents you can declare agent none and then declare the agent at each stage.

https://jenkins.io/doc/book/pipeline/jenkinsfile/#using-multiple-agents

From the docs:

pipeline {     agent none     stages {         stage('Build') {             agent any             steps {                 checkout scm                 sh 'make'                 stash includes: '**/target/*.jar', name: 'app'              }         }         stage('Test on Linux') {             agent {                  label 'linux'             }             steps {                 unstash 'app'                  sh 'make check'             }             post {                 always {                     junit '**/target/*.xml'                 }             }         }         stage('Test on Windows') {             agent {                 label 'windows'             }             steps {                 unstash 'app'                 bat 'make check'              }             post {                 always {                     junit '**/target/*.xml'                 }             }         }     } } 

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable