Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-51144

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Major Major
    • job-dsl-plugin
    • 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"  ... }
      

            daspilker Daniel Spilker
            aarondmarasco_vsi Aaron D. Marasco
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: