0

Due to infrastructure constraints, in my Jenkinsfile, I would like to store some variables from build #1 and be able to access them from build #2 and next ones.

I tried to set some env variables, but it seems they are not saved from a build to another.

Is there to acheive that from Jenkinsfile? Or maybe to write them to a text file?

Jenkins version: 2.111

Jocelyn
  • 277
  • 4
  • 21

2 Answers2

0

Yes, write them to a text file, and store that as a build artifact in build#1.

Later builds can access the text file as build#1's build artifact (via Web interface, or on disk if running on master).

Alex O
  • 7,746
  • 2
  • 25
  • 38
0

I finally use this mecanism which fits my requirements and works like a charm, so far:

if (currentBuild.previousBuild != null) {
    env.MY_VAR = currentBuild.previousBuild.getBuildVariables().get('MY_VAR ')
    echo "Old branch context restored"
} else {
    env.MY_VAR = createSomethingAtFirstBuild()
    echo "New branch context created"
}
Jocelyn
  • 277
  • 4
  • 21