[JIRA] (JENKINS-54250) Disable restarting stages in jenkinsfile optionally

16 views
Skip to first unread message

jan.hoppe@heidelberg.com (JIRA)

unread,
Oct 25, 2018, 8:03:02 AM10/25/18
to jenkinsc...@googlegroups.com
Jan Hoppe updated an issue
 
Jenkins / Improvement JENKINS-54250
Disable restarting stages in jenkinsfile optionally
Change By: Jan Hoppe
Summary: Disable restarting stages in jenkinsfile optionally
Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

andrew.bayer@gmail.com (JIRA)

unread,
Nov 16, 2018, 1:25:02 PM11/16/18
to jenkinsc...@googlegroups.com
Andrew Bayer updated an issue
Change By: Andrew Bayer
Labels: stage-restart-improvements

andrew.bayer@gmail.com (JIRA)

unread,
Dec 7, 2018, 9:40:02 AM12/7/18
to jenkinsc...@googlegroups.com
Andrew Bayer commented on Improvement JENKINS-54250
 
Re: Disable restarting stages in jenkinsfile optionally

It might be worthwhile to be able to disable restarting individual stages as well as the whole Pipeline.

jan.hoppe@heidelberg.com (JIRA)

unread,
Dec 10, 2018, 3:29:02 AM12/10/18
to jenkinsc...@googlegroups.com

That's right, disabling restart for all or a single stage would be great! 

chris.maes@macq.eu (JIRA)

unread,
Jan 30, 2019, 10:36:03 AM1/30/19
to jenkinsc...@googlegroups.com

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.

edwardmlyte@gmail.com (JIRA)

unread,
Feb 7, 2019, 6:37:02 AM2/7/19
to jenkinsc...@googlegroups.com

Our company would also like this feature to ensure partial pipeline's can't be run.

edwardmlyte@gmail.com (JIRA)

unread,
Feb 7, 2019, 6:38:02 AM2/7/19
to jenkinsc...@googlegroups.com
Edward Maxwell-Lyte edited a comment on Improvement JENKINS-54250
Our company would also like this feature to ensure partial pipeline's pipelines can't be run.

chris@chrishemp.com (JIRA)

unread,
Feb 16, 2019, 9:23:03 AM2/16/19
to jenkinsc...@googlegroups.com

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

{{}}

{{}}

{{}}

chris@chrishemp.com (JIRA)

unread,
Feb 16, 2019, 9:23:05 AM2/16/19
to jenkinsc...@googlegroups.com
Chris Hemp edited a comment on Improvement JENKINS-54250
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

{{}}

{{}}

{{}}
 

manuel.delapenya@liferay.com (JIRA)

unread,
Feb 25, 2019, 10:52:02 AM2/25/19
to jenkinsc...@googlegroups.com

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

tupchii.sergii@gmail.com (JIRA)

unread,
Feb 27, 2019, 11:15:02 AM2/27/19
to jenkinsc...@googlegroups.com

+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.

jonathan.sokolowski@gmail.com (JIRA)

unread,
Mar 24, 2019, 6:38:02 PM3/24/19
to jenkinsc...@googlegroups.com

I've written a share pipeline script to achieve this as a workaround:

#!/usr/bin/env groovy

@NonCPS
def call() {
    script {
        restartedFromStage = currentBuild.rawBuild.getCauses().any { cause ->
            cause.getClass().getName() ==~ /^.*RestartDeclarativePipelineCause$/
        }
        if (restartedFromStage) {
            error 'Restarting build from a stage is disabled. Please rerun build from start.'
        }
    }
}

jonathan.sokolowski@gmail.com (JIRA)

unread,
Mar 24, 2019, 6:39:03 PM3/24/19
to jenkinsc...@googlegroups.com
Jonathan Sokolowski edited a comment on Improvement JENKINS-54250
I've written a share shared pipeline script to achieve this as a workaround:

{code:java}

#!/usr/bin/env groovy

@NonCPS
def call() {
    script {
        restartedFromStage = currentBuild.rawBuild.getCauses().any { cause ->
            cause.getClass().getName() ==~ /^.*RestartDeclarativePipelineCause$/
        }
        if (restartedFromStage) {
            error 'Restarting build from a stage is disabled. Please rerun build from start.'
        }
    }
}
{code}

jonathan.sokolowski@gmail.com (JIRA)

unread,
Mar 24, 2019, 8:14:03 PM3/24/19
to jenkinsc...@googlegroups.com
Jonathan Sokolowski edited a comment on Improvement JENKINS-54250
I've written a shared pipeline script to achieve this as a workaround:


{code:java}
#!/usr/bin/env groovy

@NonCPS
def call() {
    script {
        restartedFromStage = currentBuild. rawBuild.getCauses getBuildCauses ().any { cause ->
            cause.
getClass().getName() _class == ~ /^ 'org . * jenkinsci.plugins.pipeline.modeldefinition.causes. RestartDeclarativePipelineCause $/ '
        }
        if (restartedFromStage) {
            error 'Restarting build from a stage is disabled. Please rerun build from start.'
        }
    }
}
{code}

chris@chrishemp.com (JIRA)

unread,
Mar 25, 2019, 7:50:02 AM3/25/19
to jenkinsc...@googlegroups.com

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

shamil.si@gmail.com (JIRA)

unread,
Jun 19, 2019, 8:40:02 AM6/19/19
to jenkinsc...@googlegroups.com

Jonathan Sokolowski thanks for the script. Question, where do I put this shared step inside my pipeline? Do I must put it in each stage?

chrismaes87@gmail.com (JIRA)

unread,
Oct 7, 2019, 4:43:03 AM10/7/19
to jenkinsc...@googlegroups.com

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?

This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

jrhett@netconsonance.com (JIRA)

unread,
Oct 9, 2019, 9:58:03 PM10/9/19
to jenkinsc...@googlegroups.com
Jo Rhett commented on Improvement JENKINS-54250

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.

suganyaravi@hotmail.com (JIRA)

unread,
Oct 15, 2019, 5:51:03 PM10/15/19
to jenkinsc...@googlegroups.com

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 {
...

suganyaravi@hotmail.com (JIRA)

unread,
Oct 15, 2019, 5:52:03 PM10/15/19
to jenkinsc...@googlegroups.com
Suganya Ravikumar edited a comment on Improvement JENKINS-54250

suganyaravi@hotmail.com (JIRA)

unread,
Oct 15, 2019, 5:52:05 PM10/15/19
to jenkinsc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages