Created
July 22, 2024 12:25
-
-
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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