How to Change Port for Jenkins

December 29, 2021

Introduction

Jenkins uses port 8080 by default. However, it also allows users to change the default port to suit their preferences.

In this tutorial, we will go over different methods of changing the default port for Jenkins.

How to change port for Jenkins

Prerequisites

  • A copy of Jenkins installed and ready to use (learn how to install Jenkins on Ubuntu 18.04, Debian 10, CentOS 8, or Windows 10).
  • Access to a web browser.
  • Access to a text editor, such as Nano (Linux and macOS) or Notepad++ (Windows).
  • Access to the terminal (Linux and macOS) or command prompt (Windows).
  • Access to a user account with sudo/administrator privileges.

Change Port for Jenkins in Windows

If you have the Jenkins application installed on a Windows system, changing the Jenkins port number requires editing the jenkins.xml configuration file. You can find this file in the Jenkins install folder (the default path is C:\Program Files\Jenkins\jenkins.xml).

Open the file using a text editor such as Notepad or Notepad++. Scroll down until you find the line that contains --httpPort=8080 and change the number to the port you want to set.

For instance, changing to port 8081:

--httpPort=8081
Changing the Jenkins port number using the configuration file in Windows

If you are using the WAR file version of Jenkins, use the following command in the command prompt to change the port number:

java -jar jenkins.war --httpPort=[port number]

Continuing with our example, to change the port number to 8081, use:

java -jar jenkins.war --httpPort=8081

Note: If you are using HTTPS with Jenkins, use java -jar jenkins.war --httpsPort=[port number] to change the port in the command prompt.

Both methods require you to restart the Jenkins service for the changes to take effect. Press Win+R to open the Run window, then type "services.msc" and click OK to start the Windows Services window.

Scroll down until you find the Jenkins service. Right-click and select Restart to restart the service.

Restarting the Jenkins service in Windows

Note: Changing the port number affects the Jenkins URL when accessing the Jenkins dashboard from your web browser. The new Jenkins URL combines your system's hostname and the new port number. Using the example above, the new Jenkins URL would be http://localhost:8081/.

Change Port for Jenkins in Linux

1. Start by opening the Jenkins configuration file with:

sudo nano /etc/default/jenkins

2. Scroll down until you find the following lines:

# port for HTTP connector (default 8080; disable with -1)
HTTP_PORT=8080

3. Edit the second line to include the port number you want to specify. For instance:

HTTP_PORT=8081
Changing the Jenkins port number using the configuration file in Linux

4. Press Ctrl+X, then type Y and press Enter to save the changes you made.

5. Restart the Jenkins service to confirm the changes:

sudo systemctl restart jenkins

Change Port for Jenkins in MacOS

1. To change the default Jenkins port number in MacOS, edit the Jenkins configuration file with:

sudo defaults write /Library/Preferences/org.jenkins-ci httpPort [port number]

2. For example, changing to port 8081:

sudo defaults write /Library/Preferences/org.jenkins-ci httpPort 8081

3. Restart the Jenkins service for the changes to take effect using the following commands:

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

Conclusion

After reading this article, you should be able to change the default port number for Jenkins to the one that best suits your needs.

Next, you might want to look into reusable Jenkins environment variables.

Was this article helpful?
YesNo
Aleksandar Kovačević
Aleksandar Kovacevic is an aspiring Technical Writer at phoenixNAP. 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
How to Restart Jenkins Manually
December 16, 2021

Jenkins offers a way for developers to automate building, testing, and deploying their applications. This tutorial show you how to restart Jenkins manually.
Read more
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
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
  • © 2021 Copyright phoenixNAP | Global IT Services. All Rights Reserved.