如何动态设置代理标签?

时间:2019-03-28 10:03:30

标签: jenkins jenkins-pipeline

我要在此处实现的目的是在同一个节点中运行多个阶段,这些阶段将在初始阶段被捕获,然后将根据需要由以下某些阶段使用。

下面是示例Jenkinsfile:

pipeline {
    agent {
    label 'redhat_linux'
}
     stages {
            stage('build') {
                    options {
                            timeout(time: 100, unit: 'SECONDS')
                    }
                    input {
                            message "Should we continue?"
                            ok "Yes, we should."
                            submitter "user1,user2"
                            parameters {
                                     string(name: 'PERSON', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')
                            }
                    }
                   steps {
                        script{
                                agentName = "${NODE_NAME}"
                                echo "The node name is :: ${agentName}"
                            }
                            sh 'pwd;ls -ltr'
                     }
            }
            stage("promote"){
                 agent{
                    node {
                        label "${agentName}"
                    } 
                }
                 steps{
                          script{
                                echo "The node name is :: ${agentName}"
                          }
                            sh 'echo "This is a promote step " '
                }
            }
         }
     }

我遇到以下错误:

groovy.lang.MissingPropertyException: No such property: agentName for class: groovy.lang.Binding

我确实从下面的链接尝试了解决方案,但是没有用。

  

In a declarative jenkins pipeline - can I set the agent label dynamically?

Jenkins版本:CloudBees Jenkins Enterprise 2.121.3.1

0 个答案:

没有答案