1

Jenkins declarative pipelines offer very convenient when directive with conditions like changeset.

Is is possible the this changeset and other when conditions in a scripted pipeline?

0

It would seem not - in the scripted pipeline, groovy needs to be used - see the docs

node {
    stage('Example') {
        if (env.BRANCH_NAME == 'master') {
            echo 'I only execute on the master branch'
        } else {
            echo 'I execute elsewhere'
        }
    }
}

(taken straight from the docs)

This would be the same as when { branch 'master' }

  • Thanks Bruce for sharing this. Well, it is obvious that one can write a code which behaves like when conditions, however both when statement and its conditions are written in java (or maybe even groovy) and, I believe, should be available from a groovy pipeline as well. – mangolier Mar 31 '20 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.