How to start jenkins on different port rather than 8080 using command prompt in Windows?
Asked Answered
M

18

146

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?

Miseno answered 7/3, 2013 at 7:18 Comment(0)
L
199

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

Ludeman answered 7/3, 2013 at 7:20 Comment(4)
Hi, I did this but after a reboot it reverted to 8080 again, is there a way to change the setting permanently?Vacla
@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.Logrolling
It lefts old 8080 and now new 9090 both are working nowGussy
@RiponAlWasim is it standard way if i use net start jenkins command to start/stop jenkins services.Gussy
K
94

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.

Kelsi answered 19/5, 2014 at 5:45 Comment(6)
Just restarting the service should suffice.Printer
I do not see this fileGogh
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'Camire
This file was called jenkins.model.JenkinsLocationConfiguration.xml for me.Takeo
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.Braun
@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.Intersexual
P
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

Pascale answered 23/1, 2015 at 9:56 Comment(4)
sadly this seems to not have any effect.it still says fail, port 8080 in use when I change to another portBorosilicate
Works on Ubuntu 18.04 tooRamonaramonda
sudo systemctl restart jenkins restarts the service, too.Golightly
I changed the port to 80 (because it is not being used by any program), but after i restart the service, the status is active but I can't open it from browser. Do you know what's wrong?Offer
P
48

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.

Pomelo answered 23/10, 2014 at 21:11 Comment(1)
This is not working in amazon linux instance. I changed the port restarted jenkins but still listening to same port.Thrombo
R
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>
Regatta answered 24/2, 2015 at 12:35 Comment(0)
M
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.

Magus answered 26/8, 2014 at 9:32 Comment(0)
G
9

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"
Golding answered 31/3, 2022 at 14:27 Comment(2)
tx. only this solution save meComplexity
Works with Ubuntu 20.04 sudo nano /etc/default/jenkins > Change the port > systemctl daemon-reload > sudo service jenkins restartHallway
S
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.

Singularity answered 29/3, 2016 at 20:10 Comment(0)
E
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.

Endorsement answered 12/2, 2015 at 15:44 Comment(0)
A
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
Agile answered 19/5, 2015 at 15:20 Comment(0)
M
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.
Masterson answered 23/2, 2016 at 16:30 Comment(0)
W
4

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

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

Wasteland answered 28/1, 2015 at 14:16 Comment(0)
J
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"
Jayjaycee answered 21/2, 2019 at 10:8 Comment(2)
it does not work for me. Jenkins refuses to start on any port except for 8080.Foresail
It was my bad, it works. I had no Custom TCP Rule on aws for the other port. Thank you.Foresail
S
3

You can call

java -jar jenkins.war --help

to see a list of all available parameters.

Sterilize answered 15/10, 2014 at 12:51 Comment(0)
K
2

On OSX edit file:

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

and edit port to you needs.

Keynote answered 7/4, 2017 at 6:1 Comment(0)
C
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

Commiserate answered 18/2, 2020 at 10:54 Comment(0)
O
1

Mac OS: 14.2.1 (23C71) [sonoma] The following command does not work for java version < 11

java -jar jenkins.war --httpPort=9090

So, first I installed jenkins with

brew install jenkins-lts

And then edited the homebrew.mxcl.jenkins-lts.plist file which is located under the following folder.

/opt/homebrew/Cellar/jenkins-lts/2.426.2

Change the port of your choice and save the file.

        ...
        <string>--httpListenAddress=127.0.0.1</string>
        <string>--httpPort=9090</string>
        ...

Then run

brew services restart jenkins-lts

And its done.

Oz answered 9/1 at 18:41 Comment(0)
T
-1

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

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

Change 8080 to whichever you want

Twelfth answered 23/7, 2014 at 6:42 Comment(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=9090Rudman

© 2022 - 2024 — McMap. All rights reserved.