Reputation: 427
So I try to set variable
base of my job {currentBuild.currentResult}
status.
script {
if ({currentBuild.currentResult} == "SUCCESS") {
HEADER_COLOR = "green"
} else {
HEADER_COLOR = "Red"
}
}
And although the job pass and the status is SUCCESS
the else condition is executed so I put print inside the else section:
else {
echo "${currentBuild.currentResult}"
HEADER_COLOR = "red"
}
And the value inside echo "${currentBuild.currentResult}"
is SUCCESS
.
Maybe I need to use this if-else
in some other way ?
Upvotes: 0
Views: 1372
Reputation: 20699
You if-else is ok, but the way you feed it with conditions is wrong.
It should be either:
if (currentBuild.currentResult == "SUCCESS") {
or (strange way)
if ("${currentBuild.currentResult}" == "SUCCESS") {
or (the hard way)
if ({currentBuild.currentResult}() == "SUCCESS") {
or (the harder way)
if ({currentBuild.currentResult}.call() == "SUCCESS") {
WHY?
Your original if
would always evaluate to false
, because you a comparing an inline-closure instance to "SUCCESS"
which is never true
.
Upvotes: 1