Issue
I have 4 different stages(build test deploy monitor) in my pipeline which is build using scripted pipeline. Pipeline runs till stage 3 completion and then waits for user input. Based on user input, I need to restart from stage 2 if the user confirms with pressing proceed after stage 3. is there any way to achieve this in scripted pipeline?
Solution
You can do something like the below to cater your requirement.
node {
def mvnHome
def flag = false
stage('Stage 1') {
echo "This stage executed always"
}
// Lets execute stage 2
generateStage2AndCall3("First Execution").call()
stage('Get User Input') {
echo "Getting user Input"
input(message: "Should we continue?")
generateStage2AndCall3("Second Execution").call()
}
stage('Stage 4') {
echo "Result"
}
}
def generateStage2AndCall3(name) {
return {
stage("Stage 2 ${name}") {
echo "Stage 2 ${name}"
generateStage3(name).call()
}
}
}
def generateStage3(name) {
return {
stage("Stage 3 ${name}") {
echo "Stage 3 ${name}"
}
}
}
The execution will look like the below.
Answered By - ycr
Answer Checked By - Robin (JavaFixing Admin)