What are the most useful `when` conditions?
IntermediateConceptDeclarative pipeline syntax
Answer
when { branch 'main' } // multibranch only, uses BRANCH_NAME
when { branch pattern: 'release/\\d+', comparator: 'REGEXP' }
when { changeRequest target: 'main' } // PR builds
when { buildingTag() } / when { tag 'v*' }
when { changeset 'services/api/**' }
when { environment name: 'DEPLOY', value: 'true' }
when { expression { params.RUN_E2E } }
when { triggeredBy 'TimerTrigger' }
when { allOf { branch 'main'; not { changeRequest() } } }
when { anyOf { branch 'main'; branch 'hotfix/*' } }
More on Declarative pipeline syntax
What is the minimum valid declarative pipeline?BeginnerWhat agent types exist in declarative pipelines?IntermediateWhen do you use `agent none` at the top level?IntermediateHow do nested sequential stages work and why are they useful?IntermediateList the `post` conditions and when each fires.IntermediateWhat do `beforeAgent`, `beforeInput` and `beforeOptions` do inside `when`?Advanced