| This sounds somewhat related to an issue i am seeing. Perhaps you can advise Andrew Bayer? I want to call some shell commands to set env vars based on other env vars, and when they are cross-referenced, they appear to get re-evaluated. Here is a basic example just using uuidgen - the use case is that the command setting SHARED_VALUE is not idempotent:
pipeline {
agent any
environment {
// SHARED_VALUE is re-evaluated each time it is referenced below
SHARED_VALUE = sh(returnStdout: true, script: """uuidgen""").trim()
TEST_ONE = sh(returnStdout: true, script: """echo '${SHARED_VALUE}' """).trim()
TEST_TWO = sh(returnStdout: true, script: """echo '${SHARED_VALUE}' """).trim()
TEST_THR = sh(returnStdout: true, script: """echo '${SHARED_VALUE}' """).trim()
}
stages {
stage('Test') {
steps {
echo "JUST TESTING"
// each of these are different UUIDs
sh '''
echo "ONE = $TEST_ONE"
echo "TWO = $TEST_TWO"
echo "THR = $TEST_THR"
'''
}
}
}
}
Is this expected behaviour? i have not found a workaround, so have reverted to a bash script in the step instead. |