-
Improvement
-
Resolution: Unresolved
-
Minor
-
None
I'd like to create two stages, where if one runs the other doesn't - effectively and `if-else`.
Right now I'd have to do something like this:
stages {
stage ('Full Build') {
when {
expression { return params.FORCE_FULL_BUILD }
}
}
stage ('Incremental Build') {
when {
expression { return !params.FORCE_FULL_BUILD }
}
}
}
For simple expressions, that's no problem. For complex expressions it gets tiresome.
The `when {}` block needs a way to indicate `else`. This could be done (when combined with a logical `not` condition) by have a `stage` condition. Like so:
stages {
stage ('Full Build') {
when {
expression { return params.FORCE_FULL_BUILD }
}
}
stage ('Incremental Build') {
when {
not { stage 'Full Build' }
}
}
}
This would also allow for stages to depend on previous stages in a clear fashion. For example:
stages {
stage ('Full Build') {
when {
expression { return params.FORCE_FULL_BUILD }
}
}
stage ('Incremental Build') {
when {
not { stage 'Full Build' }
}
}
stage ('Full Tests') {
when {
stage 'Full Build' }
}
}
stage ('Incremental Tests') {
when {
stage 'Incremental Build' }
}
}
}
- relates to
-
JENKINS-41185 [Declarative Pipeline] Stage "when" should have logical operator steps (and, or, not, all, any)
-
- Closed
-
- links to