I'm using a declarative pipeline. This part works:
steps {
script {
if ('xxx' == 'cloud') {
sh 'xxx'
} else {
sh 'xxx'
}
}
}
But I want to follow the more declarative pipeline syntax using when. I tried something like this:
stage ('Newman run') {
when {
expression { "xxx" == "cloud" }
}
steps {
echo 'Use proxy for cloud'
sh 'xx'
}
when {
expression { "cloud" == "cloud" }
}
steps {
echo 'Do not use proxy (non-cloud)'
sh 'xxx'
}
But it didn't work. How I can specify a sort of 'else
' statement after a when
in a declarative pipeline. Or if this not works, the recommended way to do this?