How to pass data between pipeline steps?

Article ID:208487668
1 minute readKnowledge base

Issue

Your pipeline script requires data during certain steps.

Environment

CloudBees Jenkins Enterprise

Resolution

The Pipeline script needs to use the results of one of the calls to determine the input data to the next call. This is possible pending JENKINS-26133 by writing the data to a file which is consumed by the next step.

Please note that the steps can be run on different nodes by doing the following:

def content
node {
  sh 'curl -s https://server/api1/resource > .resource'
  content = readFile '.resource'
}
node {
  sh "curl -s https://server/api2/${content} > .resource"
  // …
}