How to Change the Default Jenkins Port on AWS?
If you are running Jenkins on an Amazon Web Services (AWS) EC2 instance, you may need to change the default Jenkins port to ensure it doesn't conflict with other applications or to comply with your organization's security policies.
Let’s see how you can change the Jenkins port on AWS:
1. Connect to your EC2 instance using SSH.
2. Locate the Jenkins configuration file at `/etc/default/jenkins`.
3. Open the configuration file using a text editor with sudo privileges:
sudo nano /etc/default/jenkins
4. Look for the `JENKINS_PORT` variable in the configuration file. It should look something like this:
JENKINS_PORT="8080"
5. Change the port number from `8080` to your desired port number. For example, if you want to use port `9090`, modify the line as follows:
JENKINS_PORT="9090"
6. Save the changes to the configuration file by pressing `Ctrl + X`, then `Y`, and finally `Enter`.
7. Next, you need to update the security group associated with your EC2 instance to allow inbound traffic on the new port:
- Open the AWS Management Console and navigate to the EC2 dashboard.
- Click on "Security Groups" in the left sidebar.
- Find the security group associated with your EC2 instance and select it.
- Click on the "Edit inbound rules" button.
- Add a new rule with the following settings:
- Type: Custom TCP
- Protocol: TCP
- Port Range: Enter the new Jenkins port number (e.g., `9090`)
- Source: Choose the appropriate source based on your requirements (e.g., Anywhere, Custom IP, or a specific IP range)
- Click on the "Save rules" button to apply the changes.
8. Restart the Jenkins service for the changes to take effect:
sudo systemctl restart jenkins
9. After restarting Jenkins, you can access it using the new port number. Open a web browser and navigate to `http://<your-ec2-instance-public-ip>:9090`, replacing `<your-ec2-instance-public-ip>` with the public IP address of your EC2 instance.
How to Change Port for Jenkins in Windows?
Changing the Jenkins port on a Windows machine is a straightforward process. Follow these steps to modify the default Jenkins port:
1. Open the Jenkins installation directory on your Windows machine. By default, it is located at `C:\Program Files\Jenkins`.
2. Locate the `jenkins.xml` configuration file in the installation directory.
3. Open the `jenkins.xml` file using a text editor with administrative privileges, such as Notepad++.
4. Look for the `--httpPort` parameter in the `jenkins.xml` file. It should look similar to this:
<arguments>--httpPort=8080</arguments>
5. Change the port number from `8080` to your desired port number. For example, if you want to use port `9090`, modify the line as follows:
<arguments>--httpPort=9090</arguments>
6. Save the changes to the `jenkins.xml` file.
7. Open the Windows Services manager by pressing the `Windows key + R`, typing `services.msc`, and pressing `Enter`.
8. Locate the "Jenkins" service in the list of services, right-click on it, and select "Restart" to apply the changes.
9. After restarting the Jenkins service, open a web browser and navigate to `http://localhost:9090` (replace `9090` with the port number you specified in step 5) to access Jenkins using the new port.
Additionally, if you have configured Jenkins to run as a Windows service, you may need to update the service configuration:
1. Open the Windows Services manager.
2. Locate the "Jenkins" service, right-click on it, and select "Properties".
3. In the "Jenkins Service Properties" window, go to the "Log On" tab.
4. Update the "Port" field with the new port number you specified in the `jenkins.xml` file.
5. Click "Apply" and then "OK" to save the changes.
6. Restart the Jenkins service for the changes to take effect.
How to Change Port for Jenkins in MacOS?
Changing the Jenkins port on a Mac is similar to the process on other operating systems.
Let’s see how you can modify the default Jenkins port on macOS:
1. Open the Terminal application on your Mac.
2. Navigate to the Jenkins home directory using the following command:
cd /Users/Shared/Jenkins/Home
3. Locate the `jenkins.xml` configuration file in the Jenkins home directory.
4. Open the `jenkins.xml` file using a text editor with sudo privileges:
sudo nano jenkins.xml
5. Look for the `--httpPort` parameter in the `jenkins.xml` file. It should look similar to this:
<arguments>--httpPort=8080</arguments>
6. Change the port number from `8080` to your desired port number. For example, if you want to use port `9090`, modify the line as follows:
<arguments>--httpPort=9090</arguments>
7. Save the changes to the `jenkins.xml` file by pressing `Ctrl + X`, then `Y`, and finally `Enter`.
8. Next, you need to update the Jenkins launchd configuration file:
- Open the Terminal application.
- Navigate to the launchd directory using the following command:
cd /Library/LaunchDaemons
- Open the Jenkins launchd configuration file using a text editor with sudo privileges:
sudo nano org.jenkins-ci.plist
- Locate the `httpPort` parameter in the configuration file and update it with the new port number you specified in the `jenkins.xml` file.
- Save the changes to the launchd configuration file.
9. Unload the Jenkins launchd service using the following command:
sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
10. Load the updated Jenkins launchd service using the following command:
sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist
11. After reloading the Jenkins launchd service, open a web browser and navigate to `http://localhost:9090` (replace `9090` with the port number you specified in step 6) to access Jenkins using the new port.
Frequently Asked Questions
Can I use any port number for Jenkins?
Yes, you can use any available port number for Jenkins. However, make sure the port is not being used by other applications & is allowed by your firewall settings.
Do I need to restart Jenkins after changing the port?
Yes, you must restart the Jenkins service for the port changes to take effect. The specific command to restart Jenkins may vary depending on your operating system.
What should I do if the new Jenkins port is not accessible?
If the new Jenkins port is not accessible, check if the port is allowed in your firewall settings. Also, ensure that Jenkins has been restarted & no conflicting applications are using the same port.
Conclusion
In this article, we have learned how to change the default Jenkins port on various platforms, like Windows, macOS, & AWS. By modifying the Jenkins configuration files & updating the necessary settings, you can customize the port number to avoid conflicts & meet your specific requirements. Remember to restart the Jenkins service & adjust any relevant firewall or security group settings after changing the port.
You can also practice coding questions commonly asked in interviews on Coding Ninjas Code360.
Also, check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc., as well as some Contests, Test Series, and Interview Experiences curated by top Industry Experts.