Skip to content

Instantly share code, notes, and snippets.

@yarinkos
Last active June 18, 2018 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yarinkos/97161a048331e1d4ba959380a03439ce to your computer and use it in GitHub Desktop.
Save yarinkos/97161a048331e1d4ba959380a03439ce to your computer and use it in GitHub Desktop.
Get param from env var after setting by script pipeline
//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