How to Change The Jenkins Default Port Number

How to Change The Jenkins Default Port Number

To change the port that Jenkins runs on in Ubuntu, you can follow these steps:

  1. Open the Jenkins configuration file, located at /etc/default/jenkins, in a text editor.

  2. 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

  3. Save the changes and exit the text editor.

  4. Restart the Jenkins service by running the command: sudo service jenkins restart

  5. 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

  1. Access Jenkins CLI by typing the following command: java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s localhost:8080

  2. 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

  3. Restart Jenkins by running the following command: java -jar jenkins-cli.jar -s localhost:9090 -webSocket -noKeyAuth -auth user:api_token restart

  4. Verify that Jenkins is running on the new port by visiting localhost:9090 in your web browser.