As far as declarative pipelines go in Jenkins, I\'m having trouble with the when keyword.
I keep getting the error No such DSL method \'when\' found a
In the documentation of declarative pipelines, It is mentionned that you can't use when in the post block. when is allowed only inside a stage directive.
So what you can do is test the conditions using an if in a script:
post {
success {
script {
if (${env.BRANCH_NAME} == 'master')
currentBuild.result = 'SUCCESS'
}
}
// failure block
}