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.
To install Java on your system, execute the command:
$ sudo apt install openjdk-11-jre-headless
After the installation, once again verify that Java is installed:
$ java --version
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
Once the installation is complete, Jenkins should start automatically. To confirm this, run the command:
$ sudo systemctl status jenkins
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
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:
To check your server’s IP address, use the ifconfig command.
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:
To view the password, simply switch to root user and use the cat command as shown:
$ cat /var/lib/jenkins/secrets/initialAdminPassword
Copy the password and paste it in the text field shown and click the “Continue” button.
In the next step, select ‘Install suggested plugin‘ for simplicity’s sake.
Thereafter, the installation of the necessary plugin required by Jenkins will commence.
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.
The next step will populate the default URL for your Jenkin’s instance. No action is required, simply click ‘Save and Finish’.
Finally, click on the ‘Start using Jenkins’ button to gain access to Jenkins.
This ushers you to Jenkin’s dashboard as shown.
And there you have it. We have successfully managed to install Jenkins on Ubuntu 20.04 LTS.
Also Read : How to Setup Jenkins on CentOS 8 / RHEL 8