I’m trying to create a Jenkinsfile with three stages: A
, B
C
, where stage A
has these properties:
- if the git branch is
develop
thenA
always runs - for any other git branch a prompt is displayed: “Run A ?”
- if the user says ‘yes’ then
A
is run (followed byB
andC
) - if the user says ‘no’ then
A
is not run, butB
andC
are still run
- if the user says ‘yes’ then
You can do this via when condition.
I did something like this a little while ago.
pipeline {
agent any
stages {
stage('A') {
when {
anyOf {
branch 'develop'
expression {
def userInput = input(message: "Run A?", ok: 'Proceed', parameters: [choice(name: 'RunStageA', choices: ['Yes', 'No'], description: 'Select Yes to run stage A')])
return env.BRANCH_NAME != 'develop' && userInput == 'Yes'
}
}
}
steps {
echo 'Running stage A'
}
}
stage('B') {
steps {
echo 'Running stage B'
}
}
stage('C') {
steps {
echo 'Running stage C'
}
}
}
}
Try this one