Introduction

Hello, I'm Yuto Takashi from TIELEC Inc. In this article, I'll introduce how to start, stop, and restart Jenkins, a popular CI/CD tool.

Since starting, stopping, and restarting Jenkins are not frequent operations, it's easy to forget how to do them. Additionally, there are multiple methods, and it can be confusing to know which operation to use in which situation.

This article organizes these Jenkins start, stop, and restart methods. If you're struggling with Jenkins operations, please read this article.

[Updated January 2026] Added information about the latest authentication methods (API tokens) and systemd.

Summary of Jenkins Start, Stop, and Restart Methods

Jenkins start, stop, and restart methods are classified into the following patterns:

Additionally, there are multiple modes for stopping and restarting Jenkins. This article covers this information.

Stop and Restart Modes

There are six modes for stopping and restarting Jenkins:

About Authentication Methods (Important)

There have been important security changes regarding authentication methods when remotely operating Jenkins.

Using API Tokens (Recommended)

Writing passwords directly in commands is deprecated. Using API tokens is strongly recommended for the following reasons:

How to Obtain API Tokens

  1. Log in to Jenkins
  2. Click your username in the upper right corner
  3. Click "Configure"
  4. In the "API Token" section, click "Add new Token"
  5. Enter a token name and click "Generate"
  6. Copy the generated token (it will only be displayed once, so be careful)

Types of Authentication Methods

When using Jenkins CLI or API, the following authentication methods are available:

1. Specify API token directly

-auth USERNAME:API_TOKEN

2. Use environment variables

export JENKINS_USER_ID=username
export JENKINS_API_TOKEN=your_api_token

3. SSH public key authentication (disabled by default, requires configuration)

This article uses API tokens in the following command examples.

Start, Stop, and Restart Execution Patterns

Operations on Jenkins Environment

Unix-based Environments

For environments like Ubuntu or Fedora, you can operate as follows.

Note: Starting with Jenkins 2.335 and 2.332.1, the package is configured with systemd (migrated from the older System V init).

These operations forcibly stop, start, or restart Jenkins. If you want to wait for currently running Jenkins jobs to complete, use quietDown or safeRestart via URL or API as described later.

start
sudo systemctl start jenkins
stop
sudo systemctl stop jenkins
restart
sudo systemctl restart jenkins
status (check status)
sudo systemctl status jenkins

You can check if Jenkins is running normally.

Troubleshooting

To check logs:

sudo journalctl -u jenkins.service

To monitor logs in real-time:

sudo journalctl -u jenkins.service -f

Windows Environment

If you have Jenkins set up on a Windows server, there are two ways:

  1. If Jenkins is registered as a Windows service, you can operate it there.
  2. You can also operate from the command line with the following commands.
stop
C:\Program Files (x86)\Jenkins>jenkins.exe stop
start
C:\Program Files (x86)\Jenkins>jenkins.exe start
restart
C:\Program Files (x86)\Jenkins>jenkins.exe restart

Operations via Jenkins UI

You can stop or restart by logging into Jenkins as an administrator and accessing URLs.

exit
[🔗 http://<jenkins.server>/exit](http://<jenkins.server>/exit)
safe exit
[🔗 http://<jenkins.server>/safeExit](http://<jenkins.server>/safeExit)
quiet down
[🔗 http://<jenkins.server>/quietDown](http://<jenkins.server>/quietDown)
cancel quiet down
[🔗 http://<jenkins.server>/cancelQuietDown](http://<jenkins.server>/cancelQuietDown)
restart
[🔗 http://<jenkins.server>/restart](http://<jenkins.server>/restart)
safe restart
[🔗 http://<jenkins.server>/safeRestart](http://<jenkins.server>/safeRestart)
Screens During Stop/Start

enter image description here

When you open the URL, a screen like the above will appear. Click Yes to send a request to Jenkins.

enter image description here

If a screen like the above appears, click Retry using Post to send a request to Jenkins.

enter image description here

During shutdown, it will be displayed on the screen like this.

enter image description here

After executing restart, wait on this screen for a while. The screen will reload after the restart is complete.

Remote Operations of Jenkins

Security Warning: The following examples use API tokens. In actual operation, store them in environment variables or use credential files.

RemoteAPI (wget)

To stop using the wget command, use the following.

Note: Specify your username for <user> and the obtained API token for <api-token>.

exit
wget --user=<user> --password=<api-token> --post-data='' http://<jenkins.server>/exit
safe exit
wget --user=<user> --password=<api-token> --post-data='' http://<jenkins.server>/safeExit
quiet down
wget --user=<user> --password=<api-token> --post-data='' http://<jenkins.server>/quietDown
cancel quiet down
wget --user=<user> --password=<api-token> --post-data='' http://<jenkins.server>/cancelQuietDown
restart
wget --user=<user> --password=<api-token> --post-data='' http://<jenkins.server>/restart
safe restart
wget --user=<user> --password=<api-token> --post-data='' http://<jenkins.server>/safeRestart

RemoteAPI (curl)

To stop using the curl command (recommended), use the following.

exit
curl -X POST -u <user>:<api-token> http://<jenkins.server>/exit
safe exit
curl -X POST -u <user>:<api-token> http://<jenkins.server>/safeExit
quiet down
curl -X POST -u <user>:<api-token> http://<jenkins.server>/quietDown
cancel quiet down
curl -X POST -u <user>:<api-token> http://<jenkins.server>/cancelQuietDown
restart
curl -X POST -u <user>:<api-token> http://<jenkins.server>/restart
safe restart
curl -X POST -u <user>:<api-token> http://<jenkins.server>/safeRestart

Jenkins CLI

You can do the same using Jenkins CLI.

Authentication Method 1: Using -auth parameter

java -jar jenkins-cli.jar -s http://<jenkins-server>/ -auth <user>:<api-token> <command>

Authentication Method 2: Using environment variables

export JENKINS_USER_ID=<user>
export JENKINS_API_TOKEN=<api-token>
java -jar jenkins-cli.jar -s http://<jenkins-server>/ <command>
exit
java -jar jenkins-cli.jar -s http://<jenkins-server>/ -auth <user>:<api-token> shutdown
safe exit
java -jar jenkins-cli.jar -s http://<jenkins-server>/ -auth <user>:<api-token> safe-shutdown
quiet down
java -jar jenkins-cli.jar -s http://<jenkins-server>/ -auth <user>:<api-token> quiet-down
cancel quiet down
java -jar jenkins-cli.jar -s http://<jenkins-server>/ -auth <user>:<api-token> cancel-quiet-down
restart
java -jar jenkins-cli.jar -s http://<jenkins-server>/ -auth <user>:<api-token> restart
safe restart
java -jar jenkins-cli.jar -s http://<jenkins-server>/ -auth <user>:<api-token> safe-restart

Summary

Let me summarize the content again.

Jenkins start, stop, and restart methods are classified into the following patterns:

Additionally, there are normal mode and safe mode for stopping and restarting Jenkins, so use them appropriately depending on the situation.

Security Points:

References

Recommended Books

[📦 商品リンク: moshimo-book-jenkins-jissen]

[📦 商品リンク: moshimo-book-server-infra]