Install Jenkins

This will install a basic Jenkins server on a vanilla Ubuntu 22.04 LTS os CentOS 7 server.

Install Jenkins on Ubuntu

Install the JDK

sudo apt-get install openjdk-11-jdk

To ensure you have the latest fixes and features, use the project-maintained packages to install Jenkins by adding the repository key to the system

wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -

Append the Debian package repository address to the server’s sources.list:

sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

Update APT so it knows about the new packages

sudo apt-get update

Install Jenkins and its dependencies

sudo apt-get install jenkins

Start the Jenkins server

sudo systemctl start jenkins

sudo systemctl status jenkins

Unlock Jenkins on Ubuntu

Open a browser to http://:8080 where you will asked to verify the administrator password of the system to unlock Jenkins. This is done by grabbing the password from the Jenkins server.

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

You are now asked if you want to install suggest or selected plug-ins. Make your choice but suggested is probably a good starting place if you do not have a specific list you need. More can be added or removed as needed later.

Once the plug-ins are installed you will be asked to setup an admin user. Go ahead and fill in the details.

That’s it. Your Jenkins is now installed and at a basic level ready to go.

Install Jenkins on CentOS

Install the JDK

sudo yum install java-11-openjdk

Import the registry key from Jenkins

sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key

Add the repository to the system

sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo

Install Jenkins

sudo yum install jenkins

Start, enable, and verify Jenkins as a service

sudo systemctl start jenkins
sudo systemctl enable jenkins
sudo systemctl status jenkins

Configure inbound OS level firewall access

The default Jenkins installation runs on ports 8080 and 8443. Typically, HTTP/HTTPS servers run on ports 80 and 443, respectively. But these ports are considered privileged on Unix/Linux systems, and the process using them must be owned by root. Running Jenkins as root is not recommended - it should be run as its own user. Where you are wanting to run Jenkins on port 80 or 443 (i.e. HTTP/HTTPS), but you do not want to setup a proxy server you can use iptables on Linux to forward traffic.

sudo firewall-cmd --add-port=80/tcp --permanent
sudo firewall-cmd --add-port=443/tcp --permanent
sudo firewall-cmd --add-forward-port=port=80:proto=tcp:toaddr=127.0.0.1:toport=8080 --permanent
sudo firewall-cmd --add-forward-port=port=443:proto=tcp:toaddr=127.0.0.1:toport=8443 --permanent
sudo firewall-cmd --reload

Obs! If firewalld is not running on the CentOs server then you can enable it

sudo systemctl enable firewalld
sudo systemctl start firewalld
sudo systemctl status firewalld

Unlock Jenkins on CentOS

Open a browser to http://:8080 where you will asked to verify the administrator password of the system to unlock Jenkins. This is done by grabbing the password from the Jenkins server.

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

You are now asked if you want to install suggest or selected plug-ins. Make your choice but suggested is probably a good starting place if you do not have a specific list you need. More can be added or removed as needed later.

Once the plug-ins are installed you will be asked to setup an admin user. Go ahead and fill in the details.

That’s it. Your Jenkins is now installed and at a basic level ready to go.

##############################################

Configure the CentOS firewall to allow access to the Jenkins web service

With the above commands, jenkins can be configured to run on localhost:8080 and/or localhost:8443 (depending if you need or want to do SSL or not)

firewalld will then create the required iptables rules so that incoming connections on port 80 are forwarded to jenkins on 8080 (and 443 is forwarded to 8443).

sudo firewall-cmd –add-port=8080/tcp –permanent sudo firewall-cmd –reload sudo firewall-cmd –list-all

sudo firewall-cmd –add-port=80/tcp –permanent (allow incoming connections on port 80. You can also use –add-service=http instead of adding a port number) sudo firewall-cmd –add-port=443/tcp –permanent (allow incoming connections on port 443. You can also use –add-service=https instead of adding a port number) sudo firewall-cmd –add-forward-port=port=80:proto=tcp:toaddr=127.0.0.1:toport=8080 –permanent sudo firewall-cmd –add-forward-port=port=443:proto=tcp:toaddr=127.0.0.1:toport=8443 –permanent sudo firewall-cmd –reload

Last modified July 21, 2024: update (e2ae86c)