Can I define multiple agent labels in a declarative Jenkins Pipeline?

前端 未结 4 457
旧时难觅i
旧时难觅i 2020-12-24 05:17

I\'m using declarative Jenkins pipelines to run some of my build pipelines and was wondering if it is possible to define multiple agent labels.

I have a number of bu

相关标签:
4条回答
  • 2020-12-24 05:47

    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
    }
    
    0 讨论(0)
  • 2020-12-24 05:49

    This syntax appears to work for me:

    agent { label 'linux && java' }
    
    0 讨论(0)
  • 2020-12-24 05:52

    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'
                    }
                }
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-24 05:59

    Create a another label call 'small-or-medium' that has 6 all agents. Then in Jenkinsfile:

    agent { label 'small-or-medium' }
    
    0 讨论(0)
提交回复
热议问题