Thanksgiving Sale - upGrad KnowledgeHut-mobile

HomeBlogDevOpsHow to Restart Jenkins in Linux, Windows, Mac? [4 Methods]

How to Restart Jenkins in Linux, Windows, Mac? [4 Methods]

Published
24th May, 2024
Views
view count loader
Read it in
10 Mins
In this article
    How to Restart Jenkins in Linux, Windows, Mac? [4  Methods]

    While working on Jenkins, there might be instances when you need to go for Jenkins restart. Right from troubleshooting an error to installing some new Jenkins plugin, there can be various reasons why you need to restart it. However, if you are starting your days with Jenkins and do not have a complete overview of the methods you need to use to restart Jenkins manually, I have got you covered. This article comprises Jenkins tutorial to aid you in learning about ways for safe restarting Jenkins. If you want to know more about how to restart Jenkins and its different functionalities, you must check out some  Jenkins course online.

    Different Ways to Restart Jenkins

    As I mentioned earlier, there are multiple ways to restart Jenkins. You can use the URL bar, a safe restart plugin or use the Manage Jenkins tab available on the UI to restart Jenkins on your computer.

    We can segregate Jenkins restart into two different categories. The first one is to restart safely, and another way is to force restart. When you use a restart command directly on the URL, Jenkins restarts instantly without completing the build that is processing. In comparison, safe restarting allows Jenkins to complete the running builds and prepare them for the restart.  

    Users can safely restart Jenkins through the Safe Restart plugin and Manage Jenkins. 

    Using Manage Jenkins

    One can shut down and restart Jenkins using Manage Jenkins. The option to 'safe shutdown' Jenkins is available in the Tools and action section under the Manage Jenkins option. It allows you to shut down Jenkins modules safely. Using the option, Jenkins stops processing any new build and prepares for the shutdown.  

    1. Follow the steps below to understand the process completely.  
    2. First login to Jenkins  
    3. Then, select the 'Manage Jenkins' option from the left-hand side menu.  
    4. Now, scroll down and click on the 'Prepare for Shutdown' tab under 'Tools and Shutdown.' 

    Note: As you click the Prepare for Shutdown button, Jenkins will wait for the execution of the builds that are running and stop executing any new build. After clicking the Prepare for Shutdown button, you will be redirected to the Jenkins dashboard. Also, you will be shown a notification like the below image. 

    How to Restart Jenkins Manually?

    1. Restart Jenkins via URL

    Are you accessing the Jenkins dashboard from a web browser? If yes, then you can restart Jenkins manually directly from the URL. Use the following command on the URL to force restart Jenkins. It will stop Jenkins from executing any build that is running and restarts right at the time. 

    [Jenkins URL]/restart 

    Now, if you want to safely restart Jenkins, which means allowing Jenkins to execute all the builds that are running the command is a bit different. Use the below command to restart Jenkins from the URL safely:

    [Jenkins URL]/safeRestart 

    After executing any of the commands, you will be redirected to the dashboard and a notification window asking for confirmation. Click the Yes button to complete the restart. 

    The port on which Jenkins is running on your system and the hostname are available on the Jenkins URL. The default port for Jenkins to run is '8080'. 

    If you are logging in to Jenkins from your system, then you can use the following command on the URL bar: 

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

    However, if you are logging in from another system, then use these commands to restart Jenkins manually: 

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

    2. Restart Jenkins via Safe Restart Plugin

    As we mentioned earlier, you can safely restart Jenkins from the Safe Restart Plugin. If you already have the plugin installed, you can restart Jenkins straight from the dashboard left menu bar.  

    However, if you have not installed the plugin yet, you can follow the steps below to install it. 

    1. Log in to Jenkins, and from the left menu bar on the dashboard, click on Manage Jenkins. 
    2. Now, go to the System Configuration and select Manage Plugins. 
    3. Then, as the Plugin Manager window opens, click on the Available tab. 
    4. Now, on the search bar, type 'Safe restart.' From the search result, tick the box beside the plugin name. 
    5. Then add the plugin by clicking on the Install without restart button. 
    6. After installing the plugin, go back to the dashboard and click on the Restart Safely tab on the left. 
    7. Finally, you will get a notification asking for confirmation to restart Jenkins. Click Yes to proceed with the restart.  

    3. Restart Jenkins via CLI

    Jenkins command line interface is built on Java and works as an add-on to the user's native terminal shell. From the CLI, you can use Java commands to manage Jenkins. With that being said, users can restart Jenkins from the CLI itself.   

    You will be able to learn more about Jenkins and its CLI functions by participating in DevOps certification online courses.    

    However, if you want to use Jenkins CLI to restart its functions, you must check out the steps below, 

    1. In the first step, download the .jar file of the Jenkins CLI. 
    2. Now, open the Jenkins dashboard on your browser and click on the Manage Jenkins tab from the left-hand side menu bar. 
    3. Next, scroll down to the Tools and Actions section and click the Jenkins CLI button. 
    4. Download the Jenkins-cli.jar 
    5. As the download completes, open the terminal window and run the below-mentioned syntax to restart Jenkins. 
    java -jar [path to the jenkins-cli.jar file] -s [Jenkins URL] restart     

    How to Restart Jenkins in Windows, Linux, and Mac?  

    After installing Jenkins on your system, it runs as a background process. Therefore, you can easily restart Jenkins on your Linux, Windows, and Mac computer by following the simple commands you follow while restarting other services. However, we have mentioned the steps you may follow below to get the job done. Check them out now! 

    A. Restart Jenkins in Linux 

    Run the following syntax on your Linux terminal to restart Jenkins: 

    sudo systemctl restart Jenkins 

    B. Restart Jenkins in Windows

    There are two ways to restart Jenkins running on a Windows PC. Here are the steps that you need to follow, 

    1. On your Windows computer, open the Command Prompt with administrative rights. 
    2. Then, run the following command to restart Jenkins on Windows. 
    net stop Jenkins 
    net start Jenkins 

    Apart from that, there is another way that you can follow to complete the restart process. Here, you need to use a command that allows you to move to the installation folder and restart the .exe program running for Jenkins. Follow the command below to restart Jenkins on Windows using this command. 

    cd C:\Program Files\Jenkins 
    jenkins.exe restart 

    C. Restart Jenkins in MacOS

    On your Mac, you need to use the basic launchctl commands to stop and start the Jenkins services. Follow the commands here, 

    sudo launchctl unload /Library/LaunchDaemons/org.Jenkins-ci.plist 

    Restart Jenkins Stages 

    You can restart Jenkins stages once the Pipeline completes, whether it has succeeded or failed. You can do it from the Jenkins classic UI or the Blue Ocean UI itself. Here is how to do it: 

    1. Restarting from the Classic UI

    Follow the steps below to restart from stages on Jenkins:

    1. As your Pipeline completes, go to the side panel on the classic UI. 
    2. Next, locate the Restart from Stage button and click on it. 
    3. After that, you will get a list of top-level stages to choose from. Select the stage from where you want to restart. 

    As you select the stage to restart, a new build will be assigned with a new build number. Also, the previous stages will be excluded, and the Pipeline will execute the selected stage. The Pipeline will start running normally from that point.  

    Note: The list will show you only the top-level stages that were run originally following the same execution order. Also, it won't show you the skipped stages because of an earlier failure.   

    However, you will find the skipped stages because of a condition not being satisfied. The list of unavailable stages also includes the parent stage for a group of parallel stages. Along with that, the group nested stages that were supposed to be running sequentially will also be unavailable. 

    2. Restarting from the Blue Ocean UI 

    Though it's possible to restart stages from the classic UI, the Blue Ocean Plugin offers a clear and intuitive UI. It makes it easy for the users to view pipeline stages. Follow the steps below to restart Jenkins stages through Blue Ocean UI:

    1. Firstly, access your project's CI service page. 
    2. Then, select the Open Blue Ocean option from the left menu to find your project's Pipeline. 
    3. Now, select the Pipeline and click on the build you want to restart. 
    4. Then, you have to select the stage from which you want to restart. 
    5. Finally, it will start a new Jenkins run that starts from the stage that you have selected with the same commit information as it is based on.  

    Also, similar to the previous process a new description will be generated that identifies the preceding run for the build. 

    Conclusion

    Now that I've walked you through the manual restart process and other methods for restarting Jenkins, I hope you won't encounter difficulties in the future. It will now be easier for you to restart Jenkins in Linux, Windows, and Mac. However, if you need more information on Jenkins and how it works, then KnowledgeHut's  Jenkins course online can be exclusively beneficial to you. This online course will help you understand Jenkins, Jenkins restart command and its operation much better.

    Frequently Asked Questions (FAQs)

    1How to safely restart Jenkins?

    You can use the safe restart command on the Jenkins URL, the Manage Jenkins tab, or a safe restart plugin to safely restart Jenkins. Simply follow one of the methods mentioned in the article, and you can easily complete the task. 

    2How do you rerun a pipeline in Azure DevOps?

    It is pretty straightforward when it comes to running a pipeline in Azure DevOps all over again. Simply follow the steps that we have mentioned below, 

    1. Click on the Up and Down arrow on the stage box available in the pipeline window. 
    2. Now, locate and click on the Rerun button to run the particular stage. 
    3How do I keep the Jenkins pipeline after a host reboot?

    You can change sudo reboot to sudo shutdown -r +m5, or whatever delay you require would prevent the Pipeline from failing. The command separates the reboot process from the system and allows the Jenkins agent to complete the Pipeline cleanly. Thus, you can find it even after a host reboot. 

    Profile

    Mayank Modi

    Blog Author

    Mayank Modi is a Red Hat Certified Architect with expertise in DevOps and Hybrid Cloud solutions. With a passion for technology and a keen interest in Linux/Unix systems, CISCO, and Network Security, Mayank has established himself as a skilled professional in the industry. As a DevOps and Corporate trainer, he has been instrumental in providing training and guidance to individuals and organizations. With over eight years of experience, Mayank is dedicated to achieving success both personally and professionally, making significant contributions to the field of technology.

    Share This Article
    Ready to Master the Skills that Drive Your Career?

    Avail your free 1:1 mentorship session.

    Select
    Your Message (Optional)

    Upcoming DevOps Batches & Dates

    NameDateFeeKnow more
    Course advisor icon
    Course Advisor
    Whatsapp/Chat icon