How to pass data between pipeline steps?

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 http://server/api1/resource > .resource'
  content = readFile '.resource'
}
node {
  sh "curl -s http://server/api2/${content} > .resource"
  // …
}
Have more questions? Submit a request

2 Comments

  • 0
    Avatar
    Darren Graham

    typo: script in 2nd node {} should be sh 'curl....'

  • 0
    Avatar
    Denys Digtiar

    Thank you for pointing it out. I have updated the article. Not, though, that in the second node block double quotes must be used since string interpolation is involved.

Please sign in to leave a comment.