Reputation: 25
I've groovy Job DSL code (main script) in place that creates ~100 tests jobs. The approach is that they should be possible to execute manually, as well as we want to have pipelines for them to be executed at night. So, the pipeline jobs (multiple) will be created too. Not a problem.
But since the main DSL groovy script will be quite big I want the corresponding pipeline script (That the pipeline jobs will load) to be placed in separate files. Since there are so many jobs I've already placed the configuration of all jobs in a separate file where they are defined in a MAP. The logic to create all the test jobs are placed in the main script and it loops through the MAP located in separate file. Works fine.
Don't want to have the job names that must be configured in the pipeline definition hardcoded (Duplicated information)! So the plan was to create the pipeline definition files from the same main script logic that creates the test jobs. Then are all relevant information such as job names and target host etc. available for every iterations through the MAP.
Any ideas how separate pipeline script files can be created and manipulated from the groovy job dsl script?
I've tried creating files with standard groovy code. But it was obvious that they were created in the Jenkins Master. And this have to be in the slave.
def newFile = new File("${WORKSPACE}/scripts/jenkins_job_dsl/pipeline.conf")
print "${newFile}"
I got this in the seed job when the "new file" was used:
...
/home/builduser/workspace/Test_and_demo/Richard_Test/seed_job_richard/scripts/jenkins_job_dsl/pipeline.conf
FATAL: No such file or directory
13:33:50 java.io.IOException: No such file or directory
...
Upvotes: 0
Views: 611
Reputation: 1
Is your problem to read the file pipeline.conf, that already exists in the seed job?
You should be able to use readFileFromWorkspace, like this:
// read the file release.groovy from the seed job's workspace
// and configure a Groovy build step using that script
def releaseScript = readFileFromWorkspace('release.groovy')
job('example-1') {
steps {
groovyCommand(releaseScript)
}
}
// read the file run.bat from a workspace of job project-a
// and use it to configure another job
def runScript = readFileFromWorkspace('project-a', 'run.bat')
job('example-2') {
steps {
batchFile(runScript)
}
}
Upvotes: 0