在单个单独的文件中定义代理标签

bkkx9g8r  于 2022-10-06  发布在  Jenkins
关注(0)|答案(1)|浏览(73)

我目前面临一个问题,我有大约90个jenkins文件,我们最近更新了一个jenkins代理,它现在有了一个新标签,这意味着我们必须使用该代理的新标签更新每个jenkins文件,您同意这有点麻烦,特别是因为我们每次更新代理时都必须这样做。我在想,如果我们可以将所有代理定义为单个文件(变量=值),那么我们在jenkinsfile中引用变量,所以下次升级代理时,我们会在该特定文件中进行更改,而不是在90个jenkinsfile中

rur96b6h

rur96b6h1#

是的,你能做到的。我假设你在同一个SCM回购中有代理的详细信息,你有管道。在这种情况下,您可以执行如下操作。

pipeline {
    agent {label getAgentFromFile()}
    stages {
        stage('Hello6') {
            steps {
                script {
                  echo "Hello Something"                 
                }
            }
        }
   }
}

def getAgentFromFile(){
    def agent = "default"
    node {
        agent = new File( pwd() + '/agent.txt').text.trim()
        println agent
    } 
    return agent
}

相关问题