Pass variable from downstream Jenkins job to "parent" job Pass variable from downstream Jenkins job to "parent" job shell shell

Pass variable from downstream Jenkins job to "parent" job


This can be accomplished in many ways. One way would be to configure Job A to have a build step, that triggers Job B, and fetches variables in a document after Job B has finished. Then Job A can read those variables and use them in later steps.

There are several things to consider here though. First of all this requires Job B to finish before Job A can/should continue, so if you are thinking of parallel job execution this isn't ideal. Secondly, when dealing with env variables you will need a plugin to make variables available outside of the build step (exporting isn't enough), check out the EnvInject plugin. And thirdly, if job configuration is becoming complex, there probably is a better way of doing it. With Jenkinsfile and previously pipelining plugins, Job orchestration has improved a lot, and passing parameters around and such is much easier in this new, shiny world. That being said, here is an example of something that works like what you are asking about.

Job A

  1. As a build step, trigger Job B, and let Job A halt while Job B finishes

  2. As the next build step, copy an artifact from another build (Job B latest stable), using the Copy Artifact Plugin.

  3. Do something with the file, for example just printing it's content, it's now accessible in Job A.

Job B

  1. Export a variable and save it to a file

  2. Archive the written file and make it accessible to Job A.

This isn't pretty, but it works at least.

P.s. I'd recommend checking out the Jenkinsfile (https://jenkins.io/doc/book/pipeline/jenkinsfile/) options, it simplifies a lot after the initial learning curve.