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"
  // …
}
This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.