'Jenkinsfile "when" directive always skips stage, even when it shouldn't be
I've been driving myself a bit crazy since I haven't been able to get this working..
TLDR:
I want a certain stage to only run based on a specific when directive :
stage('test') {
environment{
STEPS = "${env.STEPS}"
}
when{
environment(name: "STEPS", value: "true")
}
env.STEPS is declared from a previous stage. This stage installs JQ, and reads a certain value from a json value:
stage('read json file') {
steps{
echo "Reading values from json file.."
sh "sudo apt-get -y install jq"
script {
env.STEPS = sh (returnStdout: true, script: "jq .Steps json_values.json")
echo "Steps: ${env.STEPS}"
}
}
I know it successfully reads the JSON file because it echos the correct value, which is true.
But, when the stage runs that contains the when directive, it has always skipped the stage due to when conditional. even though it seems the conditional is correct.
Any help here would be much appreciated, thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
