Maciej Szymonowicz
Maciej Szymonowicz

Reputation: 623

Reading config file in DSL build on agent host

I try to configure Jenkins' seed job, where whole business is in provided DSL script. I want to seperate that script from its configuration, which I want to locate in additional yml file. When I try to read that file:

@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)

I receive error

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

I suppose that Jenkins is looking for the file on a master host, not an agent node where workspace is located. Is it possible to read yml file in DSL build step on the agent node? Or maybe I have to execute that seed job always on my master host?

Upvotes: 0

Views: 907

Answers (1)

dge
dge

Reputation: 3075

This seems not possible as the jobDsl script is executed on master. You can try force to run the job on master with label master.

From the documentation in section Script location:

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.

Upvotes: 1

Related Questions