Automation of tasks can be quite tricky especially where multiple developers are submitting code to a shared repository. Poorly executed automation processes can often lead to inconsistencies and delays. And this is where Jenkins comes in.  Jenkins is a free and opensource continuous integration tool that’s predominantly used in the automation of tasks. It helps to streamline the continuous development, testing and deployment of newly submitted code.

In this guide, we will walk you through the installation and configuration of Jenkins on Ubuntu 20.04 LTS system.

Step 1:  Install Java with apt command

Being a Java application, Jenkins requires Java 8 and later versions to run without any issues. To check if Java is installed on your system, run the command:

$ java --version

If Java is not installed, you will get the following output.

Java-version-output-before-installation

To install Java on your system, execute the command:

$ sudo apt install openjdk-11-jre-headless

Install-Java-Ubuntu-20-04

After the installation, once again verify that Java is installed:

$ java --version

Java-version-command-ubuntu-20-04

Perfect! We now have OpenJDK installed. We can now proceed.

Step 2:  Install Jenkins via its official repository

With Java installed, we can now proceed to install Jenkins. The second step is to import the Jenkins GPG key from Jenkins repository as shown:

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

Next, configure Jenkins repository to the sources list file as shown.

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

Next, update the system’s package list.

$ sudo apt update

And install Jenkins as follows.

$ sudo apt install jenkins

Install-Jenkins-ubuntu-20-04

Once the installation is complete, Jenkins should start automatically. To confirm this, run the command:

$ sudo systemctl status jenkins

Jenkins-service-status-ubuntu-20-04

If by any chance Jenkins is not running, execute the following command to start it.

$ sudo systemctl start jenkins

Step 3: Configuring the firewall rules for Jenkins

As we have seen, Jenkins natively listens on port 8080, and if you have installed Jenkins on a server with UFW enabled, you need to open that port to allow traffic.

To enable firewall on Ubuntu 20.04 LTS run,

$ sudo ufw enable

To open port 8080 on ufw firewall, run the command:

$ sudo ufw allow 8080/tcp

Then reload the firewall to effect the changes.

$ sudo ufw reload

To confirm that port 8080 is open on the firewall, execute the command:

$ sudo ufw status

Ubuntu-firewall-status-output

From the output, we can clearly see that Port 8080 has been opened on the system.

Step 4:  Configure Jenkins with GUI

We are almost done now. The only thing remaining is to set up Jenkins using your favorite browser. So, head over to the URL bar and browse your server’s address as shown:

http://server-IP:8080

To check your server’s IP address, use the ifconfig command.

ifconfig-output-ubuntu-20-04

You will get the page similar to what we have below prompting you to provide the Administrator’s password. As per the instructions, the password is located in the file:

/var/lib/jenkins/secrets/initialAdminPassword

Unlock-Jenkins-Ubuntu-20-04

To view the password, simply switch to root user and use the cat command as shown:

$ cat /var/lib/jenkins/secrets/initialAdminPassword

Jenkins-password-Ubuntu-20-04

Copy the password and paste it in the text field shown and click the “Continue” button.

Enter-Jenkins-Password-ubuntu-20-04

In the next step, select ‘Install suggested plugin‘ for simplicity’s sake.

Install-suggested-plugins-ubuntu-20-04

Thereafter, the installation of the necessary plugin required by Jenkins will commence.

Jenkins-pulgins-installation-ubuntu-20-04

When the installation of plugins is complete, the installer will take you to the next section where you will be required to create an Admin user and click on the ‘Save and Continue’ button.

Create-Admin-User-Jenkins-Ubuntu-20-04

The next step will populate the default URL for your Jenkin’s instance. No action is required, simply click ‘Save and Finish’.

Install-Configuration-Jenkins-Ubuntu-20-04

Finally, click on the ‘Start using Jenkins’ button to gain access to Jenkins.

Jenkins-ready-portal-ubuntu-20-04

This ushers you to Jenkin’s dashboard as shown.

Jenkins-Dashboard-Ubuntu-20-04

And there you have it. We have successfully managed to install Jenkins on Ubuntu 20.04 LTS.

from Linuxtechi https://www.linuxtechi.com/install-configure-jenkins-ubuntu-20-04/