Friday, November 25, 2022

Jenkins: Safe Exit/Safe Restart

HTML Table Generator

Jenkins provides a set of administrative commands that manage Jenkins restart and shutdown (exit, safeExit, restart, and safeRestart). These commands are case-sensitive and can be invoked via a URL from a browser. 

To understand these commands, the concept of Jenkins quiet mode must be introduced. While in quiet mode, Jenkins will not start new jobs. 

When a Jenkins server is safely shut down (exited) or restarted the steps performed are:

  • Run Jenkins in quiet mode
  • Wait for jobs to complete
  • Exit or Restart Jenkins 

Exiting/Restarting Jenkins

The commands are exiting and restarting Jenkins including those taking advantage of quiet mode are case-sensitive (see below). These commands are as follows:

Command Active Jobs Action
Restart Ended without completion Restarts Jenkins server
safeRestart Completed before restart Places Jenkins in safe mode and restarts Jenkins server after all currently executing jobs are completed
Exit Ended without completion Shutsdown Jenkins server
safeExit Completed before Exit Places Jenkins in safe mode and shuts down Jenkins server after all currently executing jobs are completed


The restart, safeRestart, exit, and safeExit commands are invoked for a Jenkins server running on host <jenkins-url> as follows:

https://<jenkins-url>/restart
https://<jenkins-url>/safeRestart
https://<jenkins-url>/exit
https://<jenkins-url>/safeExit

When safeRestart or restart is invoked, Jenkins will prompt as follows:

Click on Yes to restart or navigate away to not restart.

When safeExit or exit is invoked, Jenkins will prompt as follows:


Click on "Retry using POST" to exit (shutdown) or navigate away to not exit (shutdown).

Exiting and Restarting Commands are Case Sensitive

The commands are exiting and restarting Jenkins are case sensitive. For example, attempting safeexit (incorrect) versus safeExit (correct) results in the following being displayed:


For example, attempting saferesart (incorrect) versus safeRestart (correct) results in the following being displayed:


Starting Jenkins

Starting Jenkins: Linux

To start Jenkins after shutdown on a Linux host run the following:

sudo systemctl start jenkins.service

Starting Jenkins: Windows

To start Jenkins after shutdown on a Linux host run the following:

C:\Program Files (x86)\Jenkins>jenkins.exe start

Managing Quiet Mode Explicitly

Jenkins provides commands (also case-senstive for managing quiet) that can enable and disable quiet mode unrelated to server restart or server shutdown. To enable quiet mode run the following from the browser:

https://<jenkins.server>/quietDown

To disable quiet mode run the following from the browser:

https://<jenkins.server>/cancelQuietDown

Other Ways to Restart, Exit and Enter Quiet Mode

Any URL does not need to be invoked via browser. Any of the commands described can be invoked using a variety of technologies:
  • curl: handy b/c it is cross-platform
  • sh: wget
  • PowerShell: Invoke-RestMethod
  • PostMan

No comments :

Post a Comment