Reading Time: 8 minutes

By mfitzgerald

31920.jenkins

Introduction

In this tutorial, we are going to examine Jenkins and what its purpose is. We will begin by installing it on an Ubuntu 20.04 server and then start the software, enable the service, configure it, and finally, create a user with administrative privileges.

What is Jenkins?

Jenkins is an open-source program written in the Java programming language. It is designed to provide stable and balanced Continuous Integration and Continuous Deployment (CI/CD) processes.

Why is it Needed?

Let's try to understand why this type of software is needed. Previously, when programmers wrote code and created applications, the next steps were to:

  • Build a cross-platform application that can be utilized on and transferred to any server.
  • Perform the necessary performance testing and evaluation.
  • Transfer, install, and configure the application on the servers.

These are just some of the tasks that Jenkins solves. These steps can now be automated to stabilize and speed up the development process while reducing human error. Because of this, Jenkins is one of the most widely used CI/CD solutions in use today.

Advantages

Jenkins is famous for such advantages as:

  • Increasing the reliability of the CI/CD process.
  • Ease of installation, configuration, and usage of the software.
  • A wide variety of Plugins which extends its capabilities.
  • Integration with other CI/CD tools.
  • Distribution of services. A developer can build, test, and deploy applications across multiple servers and platforms.
  • Being a free and open-source application.

Prerequisites

To install Jenkins on Ubuntu 20.04, the following requirements must be met.

  • A server with at least 2 GB RAM and 2 cores.
  • The Ubuntu 20.04 OS installed.
  • All commands are executed as the root user. If you are a normal user, you must have access to and use the sudo command.

Installation

First, we should always update Ubuntu and all installed applications.

root@host:~# apt update &&  apt upgrade -y

Install JDK

In order to install, configure, and use Jenkins, we need the Java Development Kit (JDK) installed. This tutorial will use JDK version 11 since Jenkins can use both JDK 8 and 11 versions by default. Let's begin by installing the latest version of the JDK software.

First, we check if we already have the JDK software installed on the server using the version command.

root@host:~# java -version
-bash: java: command not found
root@host:~#


Now we can install the JDK.

root@host:~# apt install openjdk-11-jdk -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  at-spi2-core ca-certificates-java fontconfig-config fonts-dejavu-core fonts-dejavu-extra java-common libatk-bridge2.0-0
  libatk-wrapper-java libatk-wrapper-java-jni libatk1.0-0 libatk1.0-data libatspi2.0-0 libavahi-client3 libavahi-common-data
  libavahi-common3 libcups2 libdrm-amdgpu1 libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libfontconfig1 libfontenc1 libgif7
  libgl1 libgl1-mesa-dri libglapi-mesa libglvnd0 libglx-mesa0 libglx0 libice-dev libice6 libjpeg-turbo8 libjpeg8 liblcms2-2
  libllvm10 libnspr4 libnss3 libpciaccess0 libpcsclite1 libpthread-stubs0-dev libsensors-config libsensors5 libsm-dev libsm6
  libvulkan1 libwayland-client0 libx11-6 libx11-data libx11-dev libx11-xcb1 libxau-dev libxaw7 libxcb-dri2-0 libxcb-dri3-0
  libxcb-glx0 libxcb-present0 libxcb-randr0 libxcb-shape0 libxcb-sync1 libxcb1 libxcb1-dev libxcomposite1 libxdamage1
  libxdmcp-dev libxext6 libxfixes3 libxft2 libxi6 libxinerama1 libxkbfile1 libxmu6 libxmuu1 libxpm4 libxrandr2 libxrender1
  libxshmfence1 libxt-dev libxt6 libxtst6 libxv1 libxxf86dga1 libxxf86vm1 mesa-vulkan-drivers openjdk-11-jdk-headless
  openjdk-11-jre openjdk-11-jre-headless x11-common x11-utils x11proto-core-dev x11proto-dev xorg-sgml-doctools xtrans-dev
Suggested packages:
  default-jre cups-common libice-doc liblcms2-utils pcscd lm-sensors libsm-doc libx11-doc libxcb-doc libxt-doc openjdk-11-demo
  openjdk-11-source visualvm libnss-mdns fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei | fonts-wqy-zenhei
  fonts-indic mesa-utils
The following NEW packages will be installed:
  at-spi2-core ca-certificates-java fontconfig-config fonts-dejavu-core fonts-dejavu-extra java-common libatk-bridge2.0-0
  libatk-wrapper-java libatk-wrapper-java-jni libatk1.0-0 libatk1.0-data libatspi2.0-0 libavahi-client3 libavahi-common-data
  libavahi-common3 libcups2 libdrm-amdgpu1 libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libfontconfig1 libfontenc1 libgif7
  libgl1 libgl1-mesa-dri libglapi-mesa libglvnd0 libglx-mesa0 libglx0 libice-dev libice6 libjpeg-turbo8 libjpeg8 liblcms2-2
  libllvm10 libnspr4 libnss3 libpciaccess0 libpcsclite1 libpthread-stubs0-dev libsensors-config libsensors5 libsm-dev libsm6
  libvulkan1 libwayland-client0 libx11-6 libx11-data libx11-dev libx11-xcb1 libxau-dev libxaw7 libxcb-dri2-0 libxcb-dri3-0
  libxcb-glx0 libxcb-present0 libxcb-randr0 libxcb-shape0 libxcb-sync1 libxcb1 libxcb1-dev libxcomposite1 libxdamage1
  libxdmcp-dev libxext6 libxfixes3 libxft2 libxi6 libxinerama1 libxkbfile1 libxmu6 libxmuu1 libxpm4 libxrandr2 libxrender1
  libxshmfence1 libxt-dev libxt6 libxtst6 libxv1 libxxf86dga1 libxxf86vm1 mesa-vulkan-drivers openjdk-11-jdk
  openjdk-11-jdk-headless openjdk-11-jre openjdk-11-jre-headless x11-common x11-utils x11proto-core-dev x11proto-dev
  xorg-sgml-doctools xtrans-dev
0 upgraded, 93 newly installed, 0 to remove and 0 not upgraded.
Need to get 309 MB of archives.
After this operation, 815 MB of additional disk space will be used.
…
…  
 …
done.
done.
root@host:~# 
 

Verify Java Version.

Lastly, we verify the Java version using this command.

root@host:~# java -version
openjdk version "11.0.9.1" 2020-11-04
OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-120.04)
OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-120.04, mixed mode)
root@host:~#

Install Jenkins

Next, we install Jenkins itself. The Jenkins version contained in the standard Ubuntu packages is different from the latest available version. Therefore, we will install the newest version from the official site.

First, we add the gpg key to verify the authenticity of the software from the repository.

root@host:~# wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | apt-key add -
OK
root@host:~#

After this, we add the repository address to our /etc/apt/sources.list.d file. This list contains information on where to download and update the application. 

root@host:~# sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > \
e>     /etc/apt/sources.list.d/jenkins.list'
root@host:~#

Next, let’s update our package list again so that the apt package manager can find the software new repository.

root@host:~# apt-get update
Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:3 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu focal-security InRelease
Ign:5 https://pkg.jenkins.io/debian-stable binary/ InRelease
Get:6 https://pkg.jenkins.io/debian-stable binary/ Release [2,044 B]
Get:7 https://pkg.jenkins.io/debian-stable binary/ Release.gpg [833 B]
Get:8 https://pkg.jenkins.io/debian-stable binary/ Packages [18.9 kB]
Fetched 21.8 kB in 1s (38.1 kB/s)
Reading package lists... Done
root@host:~#

Now we can install Jenkins.

root@host:~# apt install jenkins -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  daemon net-tools
The following NEW packages will be installed:
  daemon jenkins net-tools
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 67.2 MB of archives.
After this operation, 68.5 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/universe amd64 daemon amd64 0.6.4-1build2 [96.3 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal/main amd64 net-tools amd64 1.60+git20180626.aebd88e-1ubuntu1 [196 kB]
Get:3 https://pkg.jenkins.io/debian-stable binary/ jenkins 2.263.1 [66.9 MB]
Fetched 67.2 MB in 9s (7,112 kB/s)
Selecting previously unselected package daemon.
(Reading database ... 50086 files and directories currently installed.)
Preparing to unpack .../daemon_0.6.4-1build2_amd64.deb ...
Unpacking daemon (0.6.4-1build2) ...
Selecting previously unselected package net-tools.
Preparing to unpack .../net-tools_1.60+git20180626.aebd88e-1ubuntu1_amd64.deb ...
Unpacking net-tools (1.60+git20180626.aebd88e-1ubuntu1) ...
Selecting previously unselected package jenkins.
Preparing to unpack .../jenkins_2.263.1_all.deb ...
Unpacking jenkins (2.263.1) ...
Setting up net-tools (1.60+git20180626.aebd88e-1ubuntu1) ...
Setting up daemon (0.6.4-1build2) ...
Setting up jenkins (2.263.1) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for systemd (245.4-4ubuntu3.3) ...
root@host:~# 

Start and Verify the Service

We have installed Jenkins. Now we will start it using the systemctl system command.

root@host:~# systemctl start jenkins
root@host:~#

Next, we check to see if everything has started correctly using the systemctl status command.

root@host:~# systemctlstatusjenkinsjenkins.service -LSB: StartJenkinsatboottimeLoaded: loaded (/etc/init.d/jenkins; generated)
     Active: active (exited) sinceSat2020-12-1919:13:43 UTC; 4min35sagoDocs: man:systemd-sysv-generator(8)
      Tasks: 0 (limit: 4620)
     Memory: 0BCGroup: /system.slice/jenkins.service

Dec1919:13:42 hostsystemd[1]: StartingLSB: StartJenkinsatboottime...
Dec1919:13:42 hostjenkins[54912]: CorrectjavaversionfoundDec1919:13:42 hostjenkins[54912]:  * StartingJenkinsAutomationServerjenkinsDec1919:13:42 hostsu[54967]: (to jenkins) rootonnoneDec1919:13:42 hostsu[54967]: pam_unix(su-l:session): sessionopenedforuserjenkinsby (uid=0)
Dec1919:13:42 hostsu[54967]: pam_unix(su-l:session): sessionclosedforuserjenkinsDec1919:13:43 hostjenkins[54912]:    ...done.
Dec1919:13:43 hostsystemd[1]: StartedLSB: StartJenkinsatboottime.
root@host:~# 

Here we can see the status 

Active: active (exited) since Sat 2020-12-19 19:13:43 UTC; 4min 35s ago

Configure Firewall

So, now that our software is installed and has been launched successfully, we will begin the configuration of the server. When Jenkins is running, we must open port 8080 in the firewall so that we can access Jenkins through the browser. First, activate the UFW firewall.

root@host:~# ufw enable
Firewall is active and enabled on system startup
root@host:~#

Next, add a rule to open and use port 8080 in the firewall.

root@host:~# ufw allow 8080
Rule added
Rule added (v6)
root@host:~#  

Now, let’s check the status of the firewall.

root@host:~# ufw status
Status: active

To                         Action      From
--                         ------      ----
8080                       ALLOW       Anywhere
OpenSSH                    ALLOW       Anywhere
8080 (v6)                  ALLOW       Anywhere (v6)
OpenSSH (v6)               ALLOW       Anywhere (v6)

root@host:~#

Set up Jenkins Users

Now let's start setting up our main user. Go to a browser and enter http://YOUR_IP_OR_DOMAIN:8080

YOUR_IP_OR_DOMAIN - list your domain name or IP address here. If you don’t know your IP address, you can verify it using the following command.

root@host:~# ip a

When you enter the url into the browser, you will see the Unlock Jenkins screen. 

JenkinsMainLogin

Here we need to enter the password. To obtain the password, run the following command in the terminal to locate the password that is stored in the initialAdminPassword file. 

root@host:~# cat /var/lib/jenkins/secrets/initialAdminPassword
9654*******d9549b******2195******18
root@host:~#

Copy that password that the command output received in the terminal, and enter it in the Administrator password window below and click continue.

JenkinsMainLogin2

The next screen displays the plugins that are recommended for installation, and provides the option to select and install those plugins.

JenkinsMainLogin3

In this case, we will install the suggested plugins. After this, the recommended plugins will be installed.

JenkinsMainLogin1

After the installation is complete, you will be prompted to create a user. If you wish, you can skip this step and continue working as an administrator. Here, we will create a user.

JenkinsMainLogin4

In these fields, enter the user details.

JenkinsMainLogin5

Next, click the Save and Continue button

JenkinsReady1

Now, click the ‘Start  using Jenkins’ button and the Jenkins dashboard will open.

JenkinsWelcome1

Conclusion

In this tutorial, we have explored what Jenkins is, how to set up the prerequisites, and then install it. We then set up the firewall rules, then launched and finally configured Jenkins. After that, we created an Admin user and entered the Jenkins control panel. In moving forward, we would further counsel you to analyze and consider using Jenkins for your CI/CD pipeline.

Join Us!

We pride ourselves on being The Most Helpful Humans In Hosting™!

Our technical support staff is always available to assist with any questions you may have related to this article, 24 hours a day, 7 days a week 365 days a year.

We are available, via our ticketing systems at support@liquidweb.com, by phone (at 800-580-4986) or via Live Chat or whatever method you prefer. We work hard for you so you can relax.

About the Author: Margaret Fitzgerald

Margaret Fitzgerald previously wrote for Liquid Web.

Have Some Questions?

Our Sales and Support teams are available 24 hours by phone or e-mail to assist.

1.800.580.4985
1.517.322.0434

Latest Articles

What is Formik?

Read Article

Cloud Commerce Customer FAQ

Read Article

Five Steps to Create a Robots.txt File for Your Website

Read Article

Premium Business Email Pricing FAQ

Read Article

Microsoft Exchange Server Security Update

Read Article