In my Jenkinsfile, I have 2 stages: Pre Live and Live. I ask the user for input on stage Pre Live to know whether a deploy should be done to a pre live environment, and then on stage Live, I ask the user again for input to know whether to do a deploy to a live environment or not.
I managed to implement this. This is how the code looks:
stage("Pre Live") {
input {
message 'Deploy to Pre Live?'
parameters {
booleanParam(name: 'RELEASE_PRE_LIVE', defaultValue: false)
}
}
when {
beforeInput false
expression {
return RELEASE_PRE_LIVE.toBoolean()
}
}
steps {
// ...
}
}
stage("Live") {
input {
message 'Deploy to Live?'
parameters {
booleanParam(name: 'RELEASE_LIVE', defaultValue: false)
}
}
when {
beforeInput false
expression {
return RELEASE_LIVE.toBoolean()
}
}
steps {
// ...
}
}
What I am not able to do, however, is too keep all of this logic, but also only ask for input on the stage Live if the the previous stage (Pre Live) was executed. Normally, this could be done through the when
directive in the Live stage, but the problem is that I need my when
directive in that stage to evaluate after the input
, because I need the input
value to know if the user wants to deploy to live or not, but I also don't want to unnecessarily wait for input
on this stage if Pre Live was never ran, because it doesn't make sense.