0
0
JenkinsHow-ToBeginner · 3 min read

How to Restart Jenkins Safely Without Interrupting Jobs

To restart Jenkins safely, use the safe-restart command from the Jenkins web interface or CLI. This waits for running jobs to finish before restarting, preventing job interruption and data loss.
📐

Syntax

The safe restart command can be triggered via Jenkins web UI or CLI. It ensures Jenkins waits for all running jobs to complete before restarting.

  • Web UI: Navigate to http://your-jenkins-url/safeRestart
  • CLI: Use java -jar jenkins-cli.jar -s http://your-jenkins-url safe-restart
bash
java -jar jenkins-cli.jar -s http://your-jenkins-url safe-restart
💻

Example

This example shows how to safely restart Jenkins using the CLI. It waits for all running builds to finish before restarting Jenkins.

bash
java -jar jenkins-cli.jar -s http://localhost:8080 safe-restart
Output
Waiting for running jobs to complete... Jenkins is restarting safely.
⚠️

Common Pitfalls

Common mistakes when restarting Jenkins include:

  • Using restart instead of safe-restart, which forces immediate restart and interrupts running jobs.
  • Restarting Jenkins during critical builds causing job failures.
  • Not having proper permissions to execute restart commands.

Always prefer safe-restart to avoid job interruption.

bash
java -jar jenkins-cli.jar -s http://localhost:8080 restart
# This forces immediate restart and may interrupt jobs

java -jar jenkins-cli.jar -s http://localhost:8080 safe-restart
# This waits for jobs to finish before restarting
📊

Quick Reference

Tips for safely restarting Jenkins:

  • Use safe-restart to avoid interrupting running jobs.
  • Check Jenkins job status before restarting.
  • Ensure you have admin rights to perform restart.
  • Notify your team before restarting Jenkins.

Key Takeaways

Always use safe-restart to let running jobs finish before Jenkins restarts.
Avoid using restart command as it interrupts active jobs immediately.
Check job status and notify your team before restarting Jenkins.
Ensure you have the necessary permissions to execute restart commands.