How to Restart Jenkins Manually

December 16, 2021

Introduction

While working in Jenkins, users may be in a situation where they need to restart it manually. This can occur due to different reasons, such as troubleshooting issues or installing plugins. Luckily, Jenkins offers several methods to perform a manual restart.

In this tutorial, we will go through the different methods used to restart Jenkins manually.

How to restart Jenkins manually

Prerequisites

Restart Jenkins via URL

If you are using the Jenkins dashboard in a web browser, restart Jenkins by entering the appropriate URL. Using the default restart URL forces Jenkins to restart without waiting for any builds to complete:

[Jenkins URL]/restart

To complete all currently running jobs before the restart, use the safe restart option. New jobs will queue up and run after the restart is complete:

[Jenkins URL]/safeRestart

Both options require confirming the restart by clicking the Yes button:

Confirm the restart by clicking the Yes button

The Jenkins URL contains the system's hostname and the port Jenkins is running on (default port is 8080). If you are logging into the Jenkins dashboard on your system, use:

http://localhost:8080/restart
http://localhost:8080/safeRestart

If you are logging in on another system, use:

http://[your system's hostname]:8080/restart
http://[your system's hostname]:8080/safeRestart

Note: Check out our in-depth guide on how to change port for Jenkins in Windows, MacOS, and Linux.

Restart Jenkins via Safe Restart Plugin

The Safe Restart plugin for Jenkins allows you to perform a safe restart from the Jenkins dashboard.

1. To add the plugin, start by clicking the Manage Jenkins link on the left-hand side of the dashboard:

Open the Manage Jenkins page

2. Under the System Configuration section, click the Manage Plugins button:

Scroll down and click the Manage Plugins button

3. Under the Available tab, search for "safe restart" and check the box next to the Safe Restart plugin name.

4. Click the Install without restart button to add the plugin:

Search for "safe restart" and install the Safe Restart plugin

5. Once the plugin is installed, return to your dashboard. There is now a Restart Safely link on the left-hand side:

Click on the Restart Safely link

6. Clicking the link initiates a safe restart of Jenkins. You need to confirm the restart by clicking the Yes button:

Confirm the safe restart by clicking the Yes button

Note: Find everything you need to know about using Jenkins in our Jenkins tutorial.

Restart Jenkins via CLI

Jenkins CLI (Command Line Interface) is a Java file that works as an extension of the local terminal shell. It allows you to use Java commands to manage Jenkins from a terminal window or command prompt.

1. Start by downloading the Jenkins CLI .jar file.

2. Open the Jenkins dashboard in your web browser and click the Manage Jenkins link on the left-hand side.

3. Scroll down and click the Jenkins CLI button under the Tools and Actions section.

In the Manage Jenkins page, scroll down and click Jenkins CLI under the Tools and Actions section

4. Download jenkins-cli.jar using the provided link.

Download the Jenkins CLI Java file by clicking the link

Note: The Jenkins CLI page also offers an overview of the commands available for use.

5. Once the download is complete, open the terminal window or command prompt and use the following command syntax to restart Jenkins:

java -jar [path to the jenkins-cli.jar file] -s [Jenkins URL] restart

For instance, using the jenkins-cli.jar file in the Downloads folder on a Windows system:

java -jar C:\Users\akova\Downloads\jenkins-cli.jar -s http://localhost:8080/ restart

How to Restart the Jenkins in Linux, Windows & Mac

Once installed, Jenkins runs as a background service. This means you can restart it with the same commands used to restart any other service.

Restart the Jenkins Service in Linux

On a Linux system, initiate a restart of the Jenkins service with:

sudo systemctl restart jenkins

Another method is to use:

sudo /etc/init.d/jenkins restart

Note: Using the second method may make the Jenkins service unreliable because it picks up the environment from the root user. In contrast, restarting the service using the systemctl command provides a blank environment.

Restart the Jenkins Service in Windows

Restart the Jenkins service in the Windows command prompt by using the net command to stop and then start the service:

net stop jenkins
net start jenkins
Using the net command to restart the Jenkins service in Windows

Another method is to move to the Jenkins installation folder and restart jenkins.exe. For instance:

cd C:\Program Files\Jenkins
jenkins.exe restart
Moving to the Jenkins installation folder and restarting jenkins.exe

Restart the Jenkins Service in MacOS

To restart the Jenkins service in MacOS, stop the service and start it again using the launchctl command:

sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist

Conclusion

After reading this tutorial, you should be able to use one of the methods outlined above to restart Jenkins manually.

Was this article helpful?
YesNo
Aleksandar Kovačević
Aleksandar Kovacevic is an aspiring Technical Content Writer. With a background in both design and writing, he aims to bring a fresh perspective to writing for IT, making complicated concepts easy to understand and approach.
Next you should read
Ansible vs Kubernetes: Understanding the Differences
June 3, 2021

From tools that help with deployment and update of apps on cloud servers, to full-fledged container orchestration solutions, the automation in software development is a diverse and developing field.
Read more
Terraform vs Kubernetes: What Are the Differences
July 29, 2021

Automation is one of the most important concepts in software development today. Automating infrastructure speeds up execution of configuration changes, eliminates the human error, and provides the transparency.
Read more
Ansible Playbook: How to Create and Configure Playbooks
December 17, 2020

Ansible is a Code as Infrastructure solution for monitoring and managing remote hosts. This is done by using Ansible playbooks. This tutorial shows you how to create and run Ansible playbooks.
Read more
Helm vs Kustomize: Head-to-Head Comparison
May 27, 2021

This article will compare two popular tools that aim to simplify application deployment management, Helm and Kustomize.
Read more
  • © 2022 Copyright phoenixNAP | Global IT Services. All Rights Reserved.