Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save archmangler/76e362d5b00aa979de2fb9018983a010 to your computer and use it in GitHub Desktop.
Save archmangler/76e362d5b00aa979de2fb9018983a010 to your computer and use it in GitHub Desktop.
Jenkins Declarative Pipeline: Passing Variables between Stages and between script{} and "sh" blocs
This works:
```
def something="entity"
pipeline {
agent any
stages {
stage("hello") {
steps {
script {
echo something
something = "wintermute";
}
script {
echo "Retrieving value transported between stages" + something
AFW_MID=something
}
}
}
stage("goodbye") {
steps {
script {
env.mid = AFW_MID
echo "Getting value from last stage: ... "
echo mid
echo "Done getting value from last stage: ... "
}
//Single quote multiline shell command bloc:
sh '''
echo "Getting pipeline env variable value with interpolation " $mid
'''
}
}
}
}
```
Full issue description: https://github.com/jenkinsci/configuration-as-code-plugin/issues/2536
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment