Last active
June 18, 2018 14:35
-
-
Save yarinkos/97161a048331e1d4ba959380a03439ce to your computer and use it in GitHub Desktop.
Get param from env var after setting by script pipeline
This file contains 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
//tmp.sh export foo=bar | |
getFoo = " " | |
pipeline { | |
environment { | |
a="d" | |
// b="changeable" | |
} | |
agent { | |
node { | |
label 'master' | |
} | |
} | |
stages { | |
stage('cluster creation') { | |
steps { | |
script{ | |
// Original Map structure. | |
ALl_VARS = sh ( | |
script: 'source ./tmp.sh > /dev/null ;printenv;', | |
returnStdout: true | |
).replaceAll("[\n\r]", " "); | |
def mapEnvs = | |
//cast to map | |
ALl_VARS[1..-2] | |
// Split on , to get a List. | |
.split(' ') | |
// Each list item is transformed | |
// to a Map entry with key/value. | |
.collectEntries { entry -> | |
def pair = entry.split('=') | |
// echo pair.toString() | |
[(pair.first()): pair.last()] | |
} | |
//print foo specifically | |
print mapEnvs.foo //==bar | |
//or assign to getFoo | |
getFoo=mapEnvs.foo.toString() //==bar | |
//print getFoo | |
echo "${getFoo}" //==bar | |
} | |
} | |
} | |
} | |
} | |
return; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment