Skip to main content
A controller restart typically disrupts Freestyle jobs, but Jenkins Pipelines are checkpointed and can resume after a reboot. In this guide, you’ll modify a simple “Hello World” Pipeline to include a long-running loop, then simulate a controller failure mid-build and observe Jenkins resume from the last checkpoint.

Prerequisites

Ensure your Jenkins controller has sufficient permissions to stop and start the service via systemctl.

1. Add a Long-Running Loop to the Pipeline

Open your Pipeline’s Jenkinsfile and locate the Unit Test stage. Here’s the original Declarative Pipeline:

1.1 Why a Direct Loop Fails

If you insert a Groovy for loop directly under steps, Declarative syntax rejects it:

1.2 Wrapping the Loop in a script Block

Correct the syntax by enclosing the loop inside a script {} step:
Commit and push to main, then trigger the build in Jenkins.
The image shows a Jenkins dashboard displaying the status of a "hello-world-pipeline" with multiple build stages, some of which have failed.

2. Trigger the Build and Observe the Loop

In Pipeline Steps, you’ll see logs like:
Allow the loop to run to around step 37 before interrupting the controller.

3. Stop the Jenkins Controller Mid-Loop

SSH into your Jenkins controller and halt the service:
The image shows a terminal window in Visual Studio Code connected via SSH to a remote server named "jenkins-controller-1". The user is typing a command starting with "s".
The Pipeline log will freeze at the last echo (e.g., 38).

4. Restart Jenkins and Refresh the Console

Bring Jenkins back online:
After a few seconds, refresh the Console Output for your running job:
The image shows a Jenkins dashboard with a "Console Output" section selected for a pipeline job. The interface displays various options like "Edit Build Information," "Timings," and "Pipeline Overview."
You should see Jenkins resume:
The build continues from the last checkpoint and completes successfully.

5. Disabling Resume After Controller Restart

By default, Pipelines pick up after a restart. To enforce an abort-on-restart policy:
  1. In Jenkins, select Configure on your Pipeline project.
  2. Under Build Triggers, check Do not allow the pipeline to resume if the controller restarts.
The image shows a Jenkins configuration screen for a pipeline project, with various options like "Do not allow concurrent builds" and "Do not allow the pipeline to resume if the controller restarts."
Disabling resume will abort any in-progress Pipeline if the controller restarts. Use this only when you need a strict abort-on-restart policy.

Conclusion

Jenkins Pipelines are designed for resilience. By checkpointing the pipeline state, Jenkins can survive controller restarts and resume where it left off. Use this feature for long-running stages, or disable it when an immediate abort is required on controller failure.

References

Watch Video