-
Improvement
-
Resolution: Fixed
-
Major
-
Powered by SuggestiMate -
Declarative backlog
-
2.2121.vd87fb_6536d1e
I'd like to switch off the restart stage option.
My pipelines currently don't work correctly after restarting a stage (I check out git only at first stage...)
like that:
options {
disableResume()
disableRestart()
}
[JENKINS-54250] Disable restarting stages in jenkinsfile optionally
That's right, disabling restart for all or a single stage would be great!
the restart stage button is very confusing for many people because way more visible than the global restart (for the whole pipeline)... so disabling that would be nice.
Our company would also like this feature to ensure partial pipelines can't be run.
Our pipelines are very similar to this where restarting at a stage is confusing and rebuilds are the only option.
Pipeline stage skeleton:
- Stage 1: Checkout with a package manager install : yarn install, mvn install, gradlew build --refresh-dependencies
- Stages [1 or *]: tests
- Stages [about 5]: CI/CD pipeline
Running in a swarm, where each job could be run in a different build agent, then this restart is useless from our use case: if the swarm chooses another build agent without the previous stages already run, then the executed one fails because of the absence of build artefacts (i.e.). If this build from stage is required, I'd enforce running within the same build agent
+1 Within k8s environment, using kubernetes-plugin, and running dynamic agents makes having this option obsolete. Also took some time, and still the case, to explain people in our company, how to properly restart the job, every time, that you should actually use "replay" in this case instead.
I've written a shared pipeline script to achieve this as a workaround:
#!/usr/bin/env groovy @NonCPS def call() { script { restartedFromStage = currentBuild.getBuildCauses().any { cause -> cause._class == 'org.jenkinsci.plugins.pipeline.modeldefinition.causes.RestartDeclarativePipelineCause' } if (restartedFromStage) { error 'Restarting build from a stage is disabled. Please rerun build from start.' } } }
Previously I had the legacy UI hiding the "Restart from Stage" button with this css style (using the `simple-theme-plugin`):
/* Hide Restart from Stage */ a[href$="restart"] {display: none;}
This css style hiding solution was not an option in the Blue Ocean UI though. This helps, thanks jsok !
jsok thanks for the script. Question, where do I put this shared step inside my pipeline? Do I must put it in each stage?
jsok thanks for the script, which works fine, but this scripts generates a
expected to call pipeline.disableRestartFromStage but wound up catching script; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/
error. Is there any way to avoid this error?
shamil add it to a pipeline library as documented at https://jenkins.io/doc/book/pipeline/shared-libraries/#defining-custom-steps
Thanks jsok but I wanted to point out this doesn't solve the situation for any stage which has a when section and is also a required build step. (GitHub accepts "I didn't do this stage" as pass )
Stage "Validate changed files" skipped due to this build restarting at stage "Run downstream jobs" [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (Run downstream jobs) Stage "Run downstream jobs" skipped due to when conditional
Build shows green, let's deploy! (facepalm)
This really needs a global option.
We added the check to each stage and marked the build as ABORTED to prevent the build form going GREEN.
@NonCPS
def call() {
script {
restartedFromStage = currentBuild.getBuildCauses().any
if (restartedFromStage)
{ error 'Restarting build from a stage is disabled. Please rerun build from start.' currentBuild.result = 'ABORTED' return false }else
{ return true }}
}
in each stage we check
when {
expression
steps {
...
My team is having this issue as well. We are using the Blue Ocean UI and the pipelines in our Jenkins setup have dependent stages where Stage A must run before Stage B. Because of this, the "restart from stage" option is dangerous and should not be used. We've resorted to logic that tells the user "this is not a supported workflow" when clicked, but it would be less confusing if we could disable it entirely. Especially since the "restart from stage" button is more prevalent than the "Rerun pipeline" button.
Is there any target date for when this feature will be available in classic and Blue Ocean UIs?
There is no target date when this feature will be available ianboudreaux
should be possible to tweak https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/15978cd172a8d34e2cd6bf8a6bfeaa5514d44dad/pipeline-model-definition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/actions/RestartDeclarativePipelineAction.java#L99 to disable this at the job level via a property.
Hi. I would like to contribute to this issue, and i have even started looking into it. However, i have never before contributed to Jenkins project, and if possible, i could use some guidance, like in bullet points. Is that possible hoppej? Is this a good place to discuss implementation details?
ipdev a discussion in this issue will be seen by those who are watching the issue and may be seen by a few others. If you'd like a wider discussion forum, the Jenkins developers mailing list is a good place to discuss development questions.
If you'd like a general introduction to Jenkins plugin development, you might review the DevOps World 2021 workshop, "Contributing to Open Source", and the five part video series that came out of that workshop.
markewaite thank you very much (and sorry for the late reply). I will be reaching out to Jenkins developers via the mailing list. Looking forward to my first contribution to Jenkins project!
Hi markewaite . I've subscribed to the developers email group, wrote an email but got no response. Anything else i can do?
ipdev sorry that you didn't get a response. You can refresh the question by replying to it on the list.
Hi markewaite . I did as proposed, but still no answer. I will start creating PRs, as i would like to contribute by fixing the issue. Hopefully, i will get some communication going there. Thanks for helping out so far!
Hi! New to this thread but also need this solution for the reasons stated by the OP. Any word on this?
Even after the disableResume option is used, I see that the build state is still periodically serialized. Considering that there is no need to resume, what is the use of saving the state periodically? Shouldn't that be completely avoided?
It might be worthwhile to be able to disable restarting individual stages as well as the whole Pipeline.