首页 > 解决方案 > 在 Slave 上的 Pipeline 中运行 Groovy 脚本

问题描述

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

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

这是我的 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 中运行流水线时,我似乎总是让 Master 返回。我已经尝试在 Slave 上手动安装 Groovy,并且还删除了 Master 上的 Executors。任何运行的 Powershell 都会在从站上正确触发,并且 $NODE_NAME 值作为从站返回,但似乎只是在主站上运行的 Groovy 命令。

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

标签: jenkinsgroovyjenkins-pipeline

解决方案


推荐阅读