Skip to content

Instantly share code, notes, and snippets.

@arnlaugsson
Last active February 16, 2017 18:44
Show Gist options
  • Select an option

  • Save arnlaugsson/657387b6f206b2b65f2d0e2473c4e3d5 to your computer and use it in GitHub Desktop.

Select an option

Save arnlaugsson/657387b6f206b2b65f2d0e2473c4e3d5 to your computer and use it in GitHub Desktop.

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
    • Trigger Job B from build phase of Job A
  2. As the next build step, copy an artifact from another build (Job B latest stable), using the Copy Artifact Plugin.
    • Copy artifact from Job B
  3. Do something with the file, for example just printing it's content, it's now accessible in Job A.
    • Run a shell script that does something with the exported variable

Job B

  1. Export a variable and save it to a file
    • Write variables to a file
  2. Archive the written file and make it accessible to Job A.
    • Archive the file

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

P.s. I'd recommend checking out the Jenkinsfile options, it simplifies a lot after the initial learning curve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment