Parameters given to seed job via pipeline jobDsl don't show up as "Build Variables" in downstream's currentBuild.upstreamBuilds

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      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"  ... }
      

            Assignee:
            Daniel Spilker
            Reporter:
            Aaron D. Marasco
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Resolved:
              Archived: