Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-54250

Disable restarting stages in jenkinsfile optionally

    XMLWordPrintable

    Details

    • Similar Issues:
    • Sprint:
      Declarative backlog

      Description

      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()
      }

        Attachments

          Issue Links

            Activity

            Hide
            chrismaes Chris Maes added a comment -

            Jonathan Sokolowski 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?

            Show
            chrismaes Chris Maes added a comment - Jonathan Sokolowski 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?
            Hide
            jorhett Jo Rhett added a comment -

            Alex Simenduev add it to a pipeline library as documented at https://jenkins.io/doc/book/pipeline/shared-libraries/#defining-custom-steps

            Thanks Jonathan Sokolowski 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.

            Show
            jorhett Jo Rhett added a comment - Alex Simenduev add it to a pipeline library as documented at  https://jenkins.io/doc/book/pipeline/shared-libraries/#defining-custom-steps Thanks Jonathan Sokolowski 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.
            Hide
            suganyaravikumar Suganya Ravikumar added a comment - - edited

            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

            { 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.' currentBuild.result = 'ABORTED' return false }

            else

            { return true }

            }
            }

            in each stage we check
            when {
            expression

            { return call() }

            steps {
            ...

            Show
            suganyaravikumar Suganya Ravikumar added a comment - - edited 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 { 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.' currentBuild.result = 'ABORTED' return false } else { return true } } } in each stage we check when { expression { return call() } steps { ...
            Hide
            ianboudreaux Ian Boudreaux added a comment -

            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?

            Show
            ianboudreaux Ian Boudreaux added a comment - 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?
            Hide
            markewaite Mark Waite added a comment -

            There is no target date when this feature will be available Ian Boudreaux

            Show
            markewaite Mark Waite added a comment - There is no target date when this feature will be available Ian Boudreaux

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              hoppej Jan Hoppe
              Votes:
              32 Vote for this issue
              Watchers:
              36 Start watching this issue

                Dates

                Created:
                Updated: