How to set up Jenkins on Ubuntu 20.04?

Overview

Jenkins is a Java-based continuous integration tool used for automating the software build and continuous deployment of applications. It automates the process of building and testing project code in isolated environments. It also provides the flexibility needed by enterprises, startups, and smaller teams to create, test, rollback and deploy changes across any platform or operating system.

This tutorial will demonstrate how to install Jenkins on Ubuntu 20.04.

Prerequisites

There are certain prerequisites that need to be met before you begin.

  • JDK 8 or 11

  • Ubuntu 20.04 LTS configured with non-root sudo user privileges.

  • Stable internet connection.

  • At least 1GB of RAM.

  • Computer's hardware must be up to date.

Get Started

Step 1: Jenkins Installation

For installation on Debian, Ubuntu, and other Linux distributions, the Jenkins project offers certain packages. However, the version in the default repositories may not be the latest. To ensure you have the most up to date patches, fixes, and features, use the project's structured and well-maintained packages for successful installation.

Begin by adding a repository key to the system.

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

Once the key is entered, the system will respond with 'OK.'

We are now ready to install packages on our server. Debian 10 doesn't come with access to the Jenkins software repository by default. So, next, we will update the server's 'sources.list' file by adding Debian package repository to it.

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

Now, to avoid ending up with duplicate packages in our system, update the package lists and install Jenkins with its dependencies. You can either run these commands in a single line or separately.

sudo apt update & sudo apt install jenkins

Finally, we'll launch the Jenkins server now that Jenkins and all of its dependencies are ready.

Step 2: Launching Jenkins

You can start Jenkins service and confirm if it is running by checking its status using the systemctl commands.

sudo systemctl start jenkins.service
sudo systemctl status jenkins.service

If the Jenkins service is successfully up and running on your Ubuntu machine, you will see the status as 'active' on your terminal.

Jenkins is now operational, so let's modify the firewall rules to allow access to Jenkins from web browsers.

Step 3: Activating the Firewall

The first step in setting up a UFW firewall is to open the default port of Jenkins: 8080. This can be done using the following command:

sudo ufw allow 8080

Now, check if the firewall is active or not by using this command:

sudo ufw status

If the output of the above command is 'inactive', then the firewall is not yet activated.

To resolve this, enable OpenSSH and activate the firewall.

sudo ufw allow OpenSSH
sudo ufw enable

Now, verify the status of the firewall again to confirm if the above rules have been applied or not.

sudo ufw status

You will observe that the status is changed to 'active', and the traffic can be forwarded to port 8080 from anywhere.

Installation of Jenkins and firewall configuration are now complete. Let's begin with setting up Jenkins.

Step 4: Getting Jenkins ready

a. Using a web browser, access Jenkins on port 8080 (default) by visiting the below URL.

http://your_ipaddress:8080

If you are accessing Jenkins locally, then visit this URL.

http://localhost:8080

b. You will notice the 'Unlock Jenkins' screen. Here, you need to unlock Jenkins by entering the admin password stored in the file located in /var/lib/jenkins/secrets/initialAdminPassword.

To get the password, run the following command in the terminal:

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

The output will be an alphanumeric administrator password containing 32 characters. Copy and paste this password in the Administrator password dialog box and click Continue.

c. As Jenkins utilizes plugins to carry out continuous integration, you must install plugins to integrate it with a particular tool. You will now see 'Customize Jenkins' screen that will display two options as shown. Click on Install suggested plugins to begin the installation process.

d. The next screen will display the installation process.

e. Once the installation of plugins is successful, set up an admin account by entering the details and click on Save and Continue.

f. An 'Instance Configuration' screen will appear. Confirm your server's IP address or server's domain name for your Jenkins instance and click on Save and Finish.

g. You will now see a confirmation page stating, "Jenkins is ready!" Click on Start using Jenkins to access the Jenkins dashboard.

h. Jenkins setup is now successful.

Conclusion

This tutorial demonstrated Jenkins installation using the packages that came with the project, its launch, firewall activation, and creation of the administrator account to get started with Jenkins. You are now ready to begin exploring Jenkins.

Last updated