2

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?

1 Answer 1

1

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' }

2
  • 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.
    – Dima
    Commented Mar 31, 2020 at 14:10
  • @mangolier Those built-in keywords like stage and node are called steps. You can see all the steps available for a scripted pipeline on this page jenkins.io/doc/pipeline/steps . There is no when step.
    – Levi
    Commented Apr 16, 2023 at 23:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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