Home > front end >  How to choose node label based on an expression?
How to choose node label based on an expression?

Time:10-03

I have this example pipeline

pipeline {
    parameters {
        string(name: 'PLATFORM', description: 'target platform to build to')
    }
    agent {
        node {
            /* I want to choose 'windows-machine' 
               when PLATFORM matches "windows.*" */
            label 'linux-machine'
        }
    }
}

I want jobs that target windows platforms to run on different nodes. How can you choose node labels based on whether pipeline parameters match an expression or not?

CodePudding user response:

Instead of node, you can use agent selector label. Here is an example of how you can do this.

pipeline {
    parameters {
        string(name: 'PLATFORM', description: 'target platform to build to')
    }
    agent {label PLATFORM=='WINDOWS' ? 'windows': 'linux'}
    stages {
        stage('Test') {
            steps {
                script {
                    echo "test"
            }
        }
    }
}
}
  • Related