-
Bug
-
Resolution: Not A Defect
-
Major
-
None
-
EnvInject 2.1.5
Job DSL 1.69
Jenkins 2.107.2
I have a pipeline that calls a job dsl that calls a pipeline. We'll call them "job1", "launcher", and "job2." The idea is that I can manually run "launcher" from the Jenkins GUI, or if somebody checked a box on "job1" then it will call the launcher for you.
In the job1, I use:
jobDsl targets: "launcher_for_testing.groovy", lookupStrategy: 'JENKINS_ROOT', // Default I think additionalParameters: [ 'GIT_SELECTED_BRANCH': BRANCH_NAME, ], removedJobAction: 'DISABLE', sandbox: true
In the launcher dsl script, I can access the "GIT_SELECTED_BRANCH" variable. If manually launched, it is a parameter of the job via the Jenkins GUI and everything is fine. If it is launched via job1, it works fine too, until...
After it does a bunch of stuff to work around JENKINS-51038...
def my_job = pipelineJob("/${ROOT}/${BRANCH_FOLDER}/${pf}/build_${test}") my_job.with { description """${test} on ${pf} (${BRANCH_FOLDER})""" definition { cps { // Note: readFileFromWorkspace is SEED JOB's workspace script(readFileFromWorkspace('Jenkinsfile_job2.groovy')) sandbox() } } // Launch it! queue(my_job) // should be able to be a string too
Now, in the job2, I have this:
import groovy.json.JsonOutput currentBuild.upstreamBuilds.eachWithIndex{ val, idx -> println "upstreamBuilds[${idx}]: "+groovy.json.JsonOutput.toJson(val.getBuildVariables()) }
If I run it via job1, the build variables is empty, like noted in https://stackoverflow.com/questions/45970157/jenkins-pipeline-build-step-getbuildvariables-returns-empty-map
00:00:00.203 upstreamBuilds[0]: {}
If I launch the DSL job directly from the UI, I get
00:00:01.035 upstreamBuilds[0]: {"PATH" ... "GIT_SELECTED_BRANCH":"XXX" ... }
- is related to
-
JENKINS-51038 Re-defining existing job loses environment variables
- Closed
-
JENKINS-44128 Pass custom parameters to job-dsl via pipeline step jobDsl
- Closed