在从站的管道中运行Groovy脚本

时间:2020-05-12 08:57:44

标签: jenkins groovy jenkins-pipeline

我目前正在尝试使用Jenkins Pipeline运行Groovy代码,但是尽管我注意到了代理,但我发现我的脚本在Master而不是Slaves上运行了代码的Groovy部分。

我在Git中有一个名为JenkinsFiles的存储库,其中包含以下JenkinsFile,还有一个名为CommonLibrary的存储库,其中包含在Stages中运行的代码。

这是我的JenkinsFile:

@Library(['CommonLibrary']) _

pipeline {
    agent { label 'Slave' }
    stages {
        stage("Preparation") {
            agent { label 'Slave && Windows' }
            steps {
                Preparation()
            }
        }
    }
}

这是Preparation.groovy文件:

def call() {
    println("Running on : " + InetAddress.localHost.canonicalHostName)
}

不幸的是,当我在詹金斯(Jenkins)中运行管道时,我似乎总是能得到大师的回报。我尝试在从站上手动安装Groovy,并在主服务器上删除了执行器。任何运行的Powershell都会在Slave上正确触发,并且$ NODE_NAME值将作为Slave返回,但这只是Groovy命令似乎在Master上运行。

任何帮助将不胜感激。谢谢! -Tor

0 个答案:

没有答案