Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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;
Add Comment
Please, Sign In to add comment