I have a DSL groovy script defining a pipeline job. I need to load Jenkinsfile from the workspace. The Jenkinsfile resides in the same folder as that of the groovy script. I am trying to get the path of the groovy script programmatically so that I can use that to figure out the path of the Jenkinsfile and load it using readFileFromWorkspace
. I tried using __FILE__
directive after going through the job-dsl-wiki. But I am getting the following error:
Processing provided DSL script
ERROR: (test_job.groovy, line 3) No such property: absolutePath for class: java.lang.String
Finished: FAILURE
Here is my DSL script
job_name = "my-pipeline-job"
job_path = "${new File(__FILE__).parent.absolutePath}"
jenkinsfile = job_path + "/Jenkinsfile"
pipelineJob(job_name){
description("Jenkins pipeline job")
parameters{
stringParam("MyTestParam", "", "a sample parameter")
}
definition {
cps {
sandbox()
script(readFileFromWorkspace(jenkinsfile))
}
}
}
Is there anything that I am doing wrong here? Really appreciate any help on this.