How to Change The Jenkins Default Port Number
1 min read
To change the port that Jenkins runs on in Ubuntu, you can follow these steps:
Open the Jenkins configuration file, located at /etc/default/jenkins, in a text editor.
Locate the line that begins with HTTP_PORT and change the number to the desired port. For example, to change the port to 8081, the line should read: HTTP_PORT=8081
Save the changes and exit the text editor.
Restart the Jenkins service by running the command: sudo service jenkins restart
Verify that Jenkins is running on the new port by visiting localhost:8081 in your web browser.
Alternatively, you can use Jenkins CLI to change the port number
Access Jenkins CLI by typing the following command: java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s localhost:8080
Change the port number by running the following command: java -jar jenkins-cli.jar -s localhost:8080 -webSocket -noKeyAuth -auth user:api_token set-system-property -Dhttp.port=9090
Restart Jenkins by running the following command: java -jar jenkins-cli.jar -s localhost:9090 -webSocket -noKeyAuth -auth user:api_token restart
Verify that Jenkins is running on the new port by visiting localhost:9090 in your web browser.