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.
- 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:
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.
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)
3. Edit the second line to include the port number you want to specify. For instance:
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
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.