jenkins pipeline 声明式agent动态设置代理标签

def agentLabel

if (profile== "test") {
    agentLabel = "test"
} else if (profile== "uat") {
    agentLabel = "uat"
} else {
    agentLabel = "prd"
}

pipeline {
    agent { label agentLabel }
    
    stages{
        stage('test dynamically agent'){
            steps{
                script{
                    println agentLabel
                }
            }
        }
    }
}

参考文档