在代理主机上读取 DSL 构建中的配置文件

Reading config file in DSL build on agent host

我尝试配置 Jenkins 的种子作业,其中整个业务都在提供的 DSL 脚本中。我想将该脚本与其配置分开,我想在其他 yml 文件中找到它。当我尝试读取该文件时:

@Grab('org.yaml:snakeyaml:1.17')
import org.yaml.snakeyaml.Yaml
def workDir = SEED_JOB.getWorkspace()
def config = new Yaml().load(("${workDir}/config.yml" as File).text)

我收到错误

java.io.FileNotFoundException: /var/lib/jenkins/workspace/test.dsl/config.yml (No such file or directory)

我想 Jenkins 是在主控主机上寻找文件,而不是工作空间所在的代理节点。 是否可以在代理节点上的 DSL 构建步骤中读取 yml 文件?或者也许我必须始终在我的主控主机上执行该种子作业?

这似乎不可能,因为 jobDsl 脚本是在 master 上执行的。您可以尝试强制 运行 标签为 master.

的 master 上的作业

来自脚本位置部分的 documentation

Job DSL scripts are executed on the Jenkins master node, but the seed job's workspace which contains the script files may reside on a build node. This mean that direct access to the file specified by FILE may not be possible from a DSL script. See Distributed builds for details.