2

I am trying to change the Jenkins port from default 8080 to port 80.

so I modified the file /etc/sysconfig/jenkins and changed the variable JENKINS_PORT="8080" to JENKINS_PORT="80".

after changing the port I restarted jenkins service by systemctl restart jenkins and the service status was Active: active (exited).

I changed the port back to 8080 and after restart the service status was Active: active (running)which is good, I also tried to change the port to 8081 and the service status was Active: active (running) as well, just when I am trying to use port 80 the service status is Active: active (exited).

I tried to verify if port 80 is in use using netstat -pnltu | grep -i "80" and the port not in use, I tried to configure port 83 just for testing and I get the same behavior as port 80 configured (Active: active (exited))

Am I missing something here?

Dani Wol.
  • 258
  • 4
  • 15

5 Answers5

1

You can do it in below way:

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. You can find --httpPort=8080 and replace the 8080 with the new port number.

Restart your Jenkins server.
$ jenkins.exe restart

You can also refer How to configure Jenkins to run on port 80

Altaf
  • 2,838
  • 1
  • 16
  • 8
  • As you can see in my details I am using a Linux instance and not Windows, I changed this parameter on my Linux instance, the `--httpPort=` parameter have a variable as a value and as I mentioned I changed this variable's value from `JENKINS_PORT="8080"` to `JENKINS_PORT="80"` – Dani Wol. Jun 30 '21 at 18:41
  • @Dani Wol the link that I reffered gives answer about linux instance – Altaf Jun 30 '21 at 18:42
  • Tried this but in this example, they are using Ubuntu and I use Redhat distribution, some of the commands cannot executable. for example the `exec daemon`. – Dani Wol. Jun 30 '21 at 18:58
1

There is another solution for Linux systems that mentioned in Jenkins Documentation here

If Jenkins fails to start because a port is in use, run:

systemctl edit jenkins

and add the following:

[Service]
Environment="JENKINS_PORT=8081"

This will change the port from 8080 to 8081.

payhez
  • 27
  • 3
0

I found a solution, I changed the JENKINS_USER variable value from jenkins to root on /etc/sysconfig/jenkins.

Then I restarted Jenkins service using the command:

systemctl restart jenkins

and the service is running.

Dani Wol.
  • 258
  • 4
  • 15
  • 1
    You really do not want to be running Jenkins as root! Massive security risk. Just give jenkins sudo permission on `/usr/bin/systemctl` or `/sbin/service`. That lets root stop/start Jenkins, but Jenkins app runs as jenkins user; [much more secure](https://www.jenkins.io/doc/book/security/securing-jenkins/) – Ian W Jul 01 '21 at 00:58
  • Yeah, finally I installed Nginx and forward port 80 to 8080 and keep the jenkins_user parameter to jenkins. – Dani Wol. Jul 02 '21 at 07:22
0

Ports 0-1024 are reserved for the operating system and core services - services running as root.

Sounds like you are following the Jenkins install instructions which suggest creating a jenkins user and group - this is why you can run the app on 8080 and others greater than 1024.

Depending on your OS, edit your jenkins.service file and change these settings there.

On Centos, edit /usr/lib/systemd/system/jenkins.service or systemctl edit jenkins to make modifications to these settings. Better practice would be to use systemctl edit.. when editing systemd files.

0

To change Default Port of Jenkins in Windows while using jenkins.war use httpPort, I have created a small Video.