I have a simple pipeline job with a single stage:

timestamps {
    node ("jenkins-slave-small") {
            stage('Stage 1') {
                sh "echo 'stage2 echo'; sleep 500s"

I am testing whether or not /safeRestart waits for my pipeline to finish executing, but it seems like it's not.


[Pipeline] { (Stage 1)
[Pipeline] sh
+ echo stage2 echo
stage2 echo
+ sleep 500s
Resuming build at Thu Sep 26 18:14:18 UTC 2019 after Jenkins restart
Waiting to resume part of test-folder » test-pipeline-no-parallels #6: Finished waiting
Ready to run at Thu Sep 26 18:14:55 UTC 2019

Am I misunderstanding how /safeRestart is supposed to behave or is that the intended behaviour?

  • I don't think you are misunderstanding. I suspect that since Pipeline jobs can (theoretically) be safely suspended and resumed unlike traditional "Freestyle" jobs, safe restart doesn't need to wait for Pipeline builds to finish.
    – jayhendren
    Sep 26, 2019 at 21:51
  • Thanks @jayhendren. Is it possible to "safely" shutdown Jenkins without suspending pipeline jobs? Sep 26, 2019 at 22:01

1 Answer 1


Jenkins pipeline jobs are designed to be serializable to disk, to increase durability (their words not mine). Therefore they are considered safe to be suspended. The only things you can do is either wrap your stages in functions with @NonCPS decorator or using properties make the jobs non-resumable after restart, but this will cause them to not be resumed after restart.

Also, restarting jenkins is not really a thing that happens all the time, so it might not be worth the effort to protect against.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.