64

I installed Jenkins on a windows virtual server and want to run it as window service.

Since the port 8080 is being used by other service, I changed the http port to 8081 in jenkins.xml file. However, I am not able to launch localhost:8081/jenkins at all. I need detail instruction/steps to configure port 8081 or something to run Jenkins.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
victorialei
  • 661
  • 1
  • 6
  • 5
  • I follow the answer to change port to 8090 but Jenkins still runs at 8080 port. Anybody knows why? (note: I even clear Windows virtualstore files of my current account) – Scott Chu May 08 '17 at 03:19

16 Answers16

83
  1. Go to the directory where you installed Jenkins (by default, it's under Program Files/Jenkins)
  2. Open the Jenkins.xml configuration file
  3. Search --httpPort=8080 and replace the 8080 with the new port number that you wish
  4. Restart Jenkins for changes to take effect
Zeitounator
  • 38,476
  • 7
  • 53
  • 66
Nuh Metin Güler
  • 1,075
  • 8
  • 9
  • 1
    I placed it to 8090 but it didt work, still open jenkins with 8080 port, Should I restart the server aswell? – Ahmad Arslan Jul 09 '18 at 06:04
  • 1
    The running instance of Jenkins does not see the changes done in this file. They are only applied at startup time. – Thorbjørn Ravn Andersen Jun 14 '19 at 10:11
  • 3
    4. To restart Jenkins, go to the directory Jenkins is installed(e.g.: C:/Program Files(x86)/Jenkins) via Command Prompt & type 'jenkins.exe restart' (without quotes of course). https://stackoverflow.com/a/14869398/8696237 – Sandun Jul 20 '19 at 07:03
  • 5
    You can restart the jenkins from url like "http://jenkins_host_url:port/restart" after Jenkins.xml is updated. – fgul Dec 27 '19 at 07:34
36

Restart Jenkins service

Just restart the Jenkins service after you changed the port in jenkins.xml.

  1. Press Win + R
  2. Type "services.msc"
  3. Right click on the "Jenkins" line > Restart

    Restart Jenkins

  4. Type http://localhost:8081/ in your browser to test the change.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
35

On Ubuntu 16.04 LTS you can change the Port like that:

  1. Change port number in the config file /etc/default/jenkins to 8081 (or the port you like) HTTP_PORT=8081
  2. Restart Jenkins: service jenkins restart
user661545
  • 469
  • 4
  • 3
  • 2
    Also needed to change the port in Dashboard: **`Manage Jenkins > Configure System > Jenkins URL`** to **8081** – T.Todua Apr 13 '19 at 13:21
34

Start Jenkins from cmd line with this command :

java -jar jenkins.war --httpPort=8081

Cole9350
  • 5,444
  • 2
  • 34
  • 50
19

If you are running on Redhat, do following

  1. Stop Jenkins
    $sudo service jenkins stop

  2. change port number in /etc/sysconfig/jenkins like i did for port 8081
    JENKINS_PORT="8081"

  3. start Jenkins again
    $sudo service jenkins start

make sure your FW has correct burn rules.

Community
  • 1
  • 1
star
  • 691
  • 7
  • 12
11

In linux,

sudo vi /etc/sysconfig/jenkins

set following configuration with any available port

JENKINS_PORT="8082"
Liam
  • 27,717
  • 28
  • 128
  • 190
Udara Seneviratne
  • 2,303
  • 1
  • 33
  • 49
5

You should follow 2 steps:

  1. This step can be followed by running the cmd in the specific folder location where there will be .war file. This step helpful as Jenkins needs some disk space to perform builds and keep archives.

    set JENKINS_HOME=c:\folder\Jenkins
    
  2. This step will be helpful to change the port number, and works can be performed accordingly.

    java -jar jenkins.war --httpPort=8585
    
double-beep
  • 5,031
  • 17
  • 33
  • 41
Anirban Hazarika
  • 1,301
  • 1
  • 8
  • 3
  • 2
    While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – double-beep Aug 05 '19 at 07:32
  • 1
    Thanks, for the awareness mate, I've updated the comment that I've done. This might help now. – Anirban Hazarika Aug 05 '19 at 07:48
4

Check in Jenkins.xml and update like below

<arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8090</arguments>
Karan Thakur
  • 143
  • 2
  • 6
4

Changing Jenkins Port (METHOD 1)

sudo nano /etc/default/jenkins

Scroll down until you find the following lines:

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

HTTP_PORT=8080

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

HTTP_PORT=8081

Restart Jenkins:

sudo systemctl restart jenkins

Changing Jenkins Port (METHOD 2)

Populate /lib/systemd/system/jenkins.service with configuration parameters for the launch To change jenkins port, set Jenkins to listen on port <PORT_NUMBER>:

Open systemd service file:
sudo vi /lib/systemd/system/jenkins.service

change port:

[Service]
Environment="JENKINS_PORT=9191"

Reload units:
sudo systemctl daemon-reload

Restart jenkins:
sudo systemctl restart jenkins

More info:

https://www.jenkins.io/doc/book/installing/linux/#debianubuntu

hkimani
  • 485
  • 5
  • 14
3

1 ) Open the jenkins.xml file
2 ) Search for the "--httpPort=8080" Text and replace the port number 8080 with your custom port number (like 7070 , 9090 )
3 ) Go to your services running your machine & find out the Jenkins service and click on restart.

enter image description here

Lova Chittumuri
  • 2,994
  • 1
  • 30
  • 33
2

Use Default Port

If the default port 8080 has been bind with other process, Then kill that process.

DOS> netstat -a -o -n

Find the process id (PID) XXXX of the process which occupied 8080.

DOS> taskkill /F /PID XXXX

Now, start Jenkins (on default port)

DOS> Java -jar jenkins.war

Use Custom Port

DOS> Java -jar jenkins.war --httpPort=8008
maris
  • 718
  • 7
  • 8
  • There are multiple ways to run Jenkins when the default port "8080" is already bind with other process. Option-1: Kill the process which occupies 8080 Example: C:\Users\maris>netstat -a -n -o | find "8080" TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 2900 TCP [::]:8080 [::]:0 LISTENING 2900 C:\Users\maris>taskkill /PID 2900 /F SUCCESS: The process with PID 2900 has been terminated. C:\Users\maris> – maris Mar 27 '18 at 17:25
2

edit HTTP_PORT in config file:

sudo nano /etc/default/jenkins
# update
# HTTP_PORT=1234
# set any port you want

If this doesn't resolve the issue, set the port in jenkins.service file:

sudo nano /lib/systemd/system/jenkins.service
# update
# Environment="JENKINS_PORT=1234"
# set any port you want
sudo nano /etc/systemd/system/jenkins.service.d/override.conf
# update
# Environment="JENKINS_PORT=1234"
# set any port you want

Then restart the service by:

sudo systemctl daemon-reload
sudo systemctl restart jenkins.service
# check status by:
sudo systemctl status jenkins.service

Note: to check if a port is available to use, run:

sudo lsof -i -P -n | grep 'port_number'
# no result will show if port_number is not being used.
KIRAN KUMAR B
  • 404
  • 4
  • 8
1

For Ubuntu there is a small change in paths etc:

First, you need to open the Jenkins config file:

Path for GUI:

/etc/default/jenkins

Command for terminal:

sudo nano /etc/default/jenkins

Note: instead of nano you can use vi, cat, etc

find HTTP_PORT

replace 8080 to any port like:

HTTP_PORT=8282
Mobin Al Hassan
  • 954
  • 11
  • 22
0

On Windows (with Windows Service).

Edit the file C:\Program Files (x86)\Jenkins\jenkins.xml with 8083 if you want 8083 port.

<arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8083</arguments>
Stéphane GRILLON
  • 11,140
  • 10
  • 85
  • 154
0

For jenkins in a docker container you can use port publish option in docker run command to map jenkins port in container to different outside port.

e.g. map docker container internal jenkins GUI port 8080 to port 9090 external

docker run -it -d --name jenkins42 --restart always \
   -p <ip>:9090:8080 <image>
gaoithe
  • 4,218
  • 3
  • 30
  • 38
0

Note that since Jenkins 2.332.1, this won't work anymore, as described in the accepted answer of this post. Basically, you have to configure Jenkins using systemctl by typing

systemctl edit jenkins

then, pass in:

[Service]
Environment="JENKINS_PORT=<anyPort>"