I have a Jenkinsfile which will be triggered by GitLab (using Webhooks).
I want to skip the whole Jenkinsfile's execution if a particular condition is not met.
One way to do this is to apply the same condition on each stage
pipeline {
agent any
stages {
stage ('Stage 1') {
when {
expression {
//Expression
}
}
//do something
}
stage ('Stage 2') {
when {
expression {
//Expression
}
}
//do something
}
stage ('Stage 3') {
when {
expression {
//Expression
}
}
//do something
}
.
.
.
.
}
}
But this seems weird as I want the same condition to be applied for all the stages.
Can we apply similar condition over stages itself ? Like this?
pipeline {
agent any
stages {
when {
expression {
//Expression
}
}
stage ('Stage 1') {
//do something
}
stage ('Stage 2') {
//do something
}
stage ('Stage 3') {
//do something
}
.
.
.
.
}
}