The Jenkins project provides Docker images for controllers (and more).
Beginning with Jenkins 2.344 released April 18, 2022 and Jenkins 2.332.3 released May 04, 2022, the behavior of the "Exit" and "Restart" lifecycle of the controller image
TL;DR; Ensure that you have a Container Restart Policy
For quick readers: check the How to Add a Container Restart Policy section for immediate actions to be taken.
Jenkins previously restarted itself after upgrading plugins or via the
/safeRestart endpoints by calling
This was fragile and exposed users to a variety of bugs.
ExitLifecycle implementation allows the main process to exit normally before starting it again from scratch,
relying on the exit code to signal to the container orchestrator that the container ought to be restarted rather than to remain shut down.
exec(2) from Java code, with all the associated complexity of closing file handles and making low-level system calls via JNA, eliminates exposure to a category of bugs.
It means that when the Jenkins controller triggers any "restart" or "exit" event, then its container exits.
If you are running Jenkins in a controller as a container, you should add a "container restart policy" different than
none to ensure that the container is restarted automatically.
If you are running Jenkins in production in a container, chances are great that you already have a restart policy set and the change will be transparent.
But we updated the jenkinsci/docker documentation to mention that the flag
--restart=on-failure is set when starting a Jenkins controller container.
If you do not have a container restart policy defined, please find the different following methods depending on your container orchestrator:
Docker Engine, Docker Swarm: add the flag
docker run <…> jenkins/jenkinscommand.
No need to create a new container: you can use the command
docker updateto update the restart policy of an existing container.
Otherwise, ensure that you configure the Deployment for Jenkins to specify the
OnFailurerestart policy for the pods. Please note that it’s the default policy if unspecified.