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

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Not A Defect
    • Component/s: job-dsl-plugin
    • Labels:
      None
    • Environment:
      EnvInject 2.1.5
      Job DSL 1.69
      Jenkins 2.107.2
    • Similar Issues:

      Description

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

        Attachments

          Issue Links

            Activity

            Hide
            aarondmarasco_vsi Aaron D. Marasco added a comment -

            Linking to JENKINS-51038 because if that was fixed, I wouldn't have to be doing this history-wandering via currentBuild.upstreamBuilds...

            Show
            aarondmarasco_vsi Aaron D. Marasco added a comment - Linking to JENKINS-51038 because if that was fixed, I wouldn't have to be doing this history-wandering via currentBuild.upstreamBuilds ...
            Hide
            daspilker Daniel Spilker added a comment -

            The seed job is not an upstream job of the job's queued in the script. There is no upstream/downstream relationship between the seed job and the queued jobs.

            Show
            daspilker Daniel Spilker added a comment - The seed job is not an upstream job of the job's queued in the script. There is no upstream/downstream relationship between the seed job and the queued jobs.
            Hide
            aarondmarasco_vsi Aaron D. Marasco added a comment -

            Can I ask why it isn't? Is the "queue" command launching the job in some non-standard way? I understand the disconnect between the seed and target jobs if it was just being defined and not explicitly queued.

            Show
            aarondmarasco_vsi Aaron D. Marasco added a comment - Can I ask why it isn't? Is the " queue " command launching the job in some non-standard way? I understand the disconnect between the seed and target jobs if it was just being defined and not explicitly queued.

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: