142

I have jenkins.war and I started it from command prompt in Windows as:

java -jar jenkins.war

It was started well and easily browsed as http://localhost:8080

I want to start on 9090 port. How can I do that?

17 Answers17

197

Use the following command at command prompt:

java -jar jenkins.war --httpPort=9090

If you want to use https use the following command:

java -jar jenkins.war --httpsPort=9090

Details are here

drac_o
  • 427
  • 5
  • 11
Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
  • 5
    Hi, I did this but after a reboot it reverted to 8080 again, is there a way to change the setting permanently? – null Feb 15 '14 at 13:24
  • 1
    @SteveGreen: The above mentioned commands are starting Jenkins from the command line. This is not a permant configuration. It is possible to save this command in a batch file and launch that file during startup, e.g. in an autostart folder. – Christian Apr 24 '14 at 12:35
  • It lefts old 8080 and now new 9090 both are working now – Ashish Kamble Dec 12 '18 at 07:43
  • @RiponAlWasim is it standard way if i use `net start jenkins` command to start/stop jenkins services. – Ashish Kamble Dec 13 '18 at 05:15
93

Open the jenkins.xml in the jenkins home folder (usually C:\Program Files (x86)\Jenkins) and change the port number:
httpPort=xxxx
to
httpPort=yyyy
then restart the service. it should change the setting permanently.

Aaron D
  • 5,817
  • 1
  • 36
  • 51
Prasad
  • 939
  • 6
  • 2
  • 1
    Just restarting the service should suffice. – adarshr Aug 05 '14 at 22:02
  • 7
    I do not see this file – Erik Aug 19 '14 at 17:45
  • Might be worth pointing out that 'jenkins.xml' is the one located in the same folder as jenkins.exe. Not the one that you may have copied to folder pointed to by environment variable 'JENKINS_HOME' – Travis Jun 05 '15 at 20:02
  • 3
    This file was called `jenkins.model.JenkinsLocationConfiguration.xml` for me. – Oscar Barrett Nov 02 '15 at 03:13
  • 1
    I would like to add that if you are not able to edit the jenkins.xml file on Windows for some reason, drag the file to your desktop. It will let you edit it there. Once you make the changes, drag the file back into the installation directory and restart the service. Big thanks to Prasad for the answer. – Jubl May 09 '16 at 22:06
  • @Jubl: You're a lifesaver! Despite changing the default instance port upon initial Jenkins configuration, verifying that `jenkins.xml` had the correct `httpPort`, and restarting the Windows service, it still didn't work. Dragging the file to my desktop (which then reverted the default port back to 8080), editing it, putting it back into the installation folder, and then restarting the service made it work. – blackcompe Jul 15 '18 at 16:12
93

With Ubuntu 14.4 I had to change the file /etc/default/jenkins

E.g.

   #HTTP_PORT=8080
   HTTP_PORT=8083

and restart the service

service jenkins restart

christian
  • 9,412
  • 10
  • 41
  • 51
49

In CentOS/RedHat (assuming you installed the jenkins package)

vim /etc/sysconfig/jenkins

....
# Port Jenkins is listening on.
# Set to -1 to disable
#
JENKINS_PORT="8080"

change it to any port you want.

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
kanibalv
  • 601
  • 5
  • 4
  • 3
    This is not working in amazon linux instance. I changed the port restarted jenkins but still listening to same port. – manukyanv07 Mar 16 '22 at 09:52
13

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>
Aaron D
  • 5,817
  • 1
  • 36
  • 51
Stéphane GRILLON
  • 11,140
  • 10
  • 85
  • 154
10

For the benefit of Linux users who find themselves here: I found /etc/sysconfig/jenkins has a JENKINS_PORT="8080", which you should probably change too.

djb
  • 1,635
  • 3
  • 26
  • 49
7

On Debian 11 it ignores /etc/default/jenkins file. Instead you open /usr/lib/systemd/system/jenkins.service file and replace http-port there in the string:

Environment="JENKINS_PORT=8080"
Almaz
  • 920
  • 11
  • 13
6

In *nix In CentOS/RedHat

vim /etc/sysconfig/jenkins

# Port Jenkins is listening on.
# Set to -1 to disable
#
JENKINS_PORT="8080"

In windows open XML file C:\Program Files (x86)\Jenkins\jenkins.xml

<executable>%BASE%\jre\bin\java</executable>
  <arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --**httpPort=8083**</arguments>
 i made  above bold  to show you change then 
 <executable>%BASE%\jre\bin\java</executable>
  <arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8083</arguments>

now you have to restart it doesnot work unless you restart http://localhost:8080/restart then after restart http://localhost:8083/ all should be well so looks like the all above response which says it does not work We have restart.

Jin Thakur
  • 2,711
  • 18
  • 15
5

For Fedora, RedHat, CentOS and alike, any customization should be done within /etc/sysconfig/jenkins instead of /etc/init.d/jenkins. The purpose of the first file is exactly the customization of the second file.

So, within /etc/sysconfig/jenkins, there is a the JENKINS_PORT variable that holds the port number on which Jenkins is running.

Younes
  • 1,635
  • 1
  • 19
  • 33
5

Correct, use --httpPort parameter. If you also want to specify the $JENKINS_HOME, you can do like this:

java -DJENKINS_HOME=/Users/Heros/jenkins -jar jenkins.war  --httpPort=8484
mainframer
  • 20,411
  • 12
  • 49
  • 68
5

To change the default port of 8080. All you need to do:

  1. Goto Jenkins folder present in C:\Program Files (x86)
  2. Open a notepad or text pad and run them as administrator and then try opening the jenkins.xml file present in the jenkins folder.
  3. Change the port number as below: <arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=9090</arguments>
  4. Click Save.
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Vinodh Aj
  • 97
  • 2
  • 3
4

Add the following two lines after DAEMON_ARGS in the file /etc/init.d/jenkins

HTTP_PORT=8010
JENKINS_ARGS="--httpPort=$HTTP_PORT"

Vimal Mathew
  • 575
  • 3
  • 10
4

If you have configured jenkins on ec2 instance with linux AMI and looking to change the port. Edit the file at

sudo vi /etc/sysconfig/jenkins

Edit

JENKINS_PORT="your port number"

Exit vim

:wq

Restart jenkins

sudo service jenkins restart

Or simply start it, if its not already running

sudo service jenkins start

To verify if your jenkins is running on mentioned port

netstat -lntu | grep "your port number"
Ankush Singh
  • 560
  • 7
  • 17
3

You can call

java -jar jenkins.war --help

to see a list of all available parameters.

Thomas Schütt
  • 832
  • 10
  • 14
2

On OSX edit file:

/usr/local/Cellar/jenkins-lts/2.46.1/homebrew.mxcl.jenkins-lts.plist

and edit port to you needs.

Sagar V
  • 12,158
  • 7
  • 41
  • 68
Pauls Bebris
  • 399
  • 4
  • 6
1

Open Command Prompt as Administrator in Windows . Go to the directory where Jenkins is installed. and stop the Jenkins service first, using jenkins.exe stop

type the command to change the port using, java -jar jenkins.war --httpPort=9090 (enter the port number you want to use).

and at-last, restart the Jenkins services, using jenkins.exe restart

-1

Change the '/etc/init.d/jenkins' shell

check_tcp_port "http" "$HTTP_PORT" "8080" || return 1

Change 8080 to whichever you want

Kamel
  • 1,856
  • 1
  • 15
  • 25
  • 1
    1. There is no /etc directory in Windows. 2. This is only a check if the port is already in use. You can change it in Ubuntu/Debian in /etc/default/jenkins: HTTP_PORT=9090 – Spartan Aug 11 '14 at 12:16