I have a scripted pipeline with one stage where I need to set the result of current build based on the output of a shell script. Unfortunately it looks that setting value with the shell script doesn't change the value of variable created using withEnv.
Is anyone able to pinpoint the mistake in the simplified snippet below (if there is one) or suggest some other solution?
stage('MyStage') {
withEnv(["MY_VAR=null"]) {
if (env.someCondition1 || env.someCondition2) {
sh '''#!/bin/bash
echo $MY_VAR # null
export MY_VAR="UNSTABLE"
printenv | grep MY_VAR # MY_VAR="UNSTABLE"
'''
}
echo env.MY_VAR // null
currentBuild.result = env.MY_VAR
echo currentBuild.result // FAILURE
}
}