Jenkins is a free and open-source automation server written in Java. It can be deployed on a single server or as a distributed application. It is one of the most popular open-source solutions for continuous integration and continuous delivery of software applications.
Continuous integration (CI) is a software development practice that requires developers to integrate their code into the main repository (usually on a daily basis) as early and often as possible in order to detect integration errors, build new features, and provide feedback for all stages of the software life cycle.
A platform like Jenkins is a CI framework that can be used online or installed locally on your computer. It provides you with an easy-to-use interface for collaborating with your team members on GitHub, Bitbucket, or other repositories that use Git in order to create continuous integration pipelines.
Continuous delivery (CD) is a software development practice that enables small, frequent releases of software applications and services. It is faster than the traditional approach, which typically involves a single large release every six months. Continuous delivery can include deploying new code every day, every hour, or even several times an hour. The shorter time intervals enable flexibility in response to changes in business requirements or underlying technology while also lowering the cost and risk associated with long periods of time between releases.
A platform like Jenkins is a CD framework that coordinates and manages the different steps required to produce a CD system. The role of Jenkins is not just to build the code, but also to test and deploy it.
A plugin-based architecture that allows extending the basic functionality of Jenkins with self-written plugins, e.g. for source code management or other tasks. The available plugins are listed in the Plugin Manager within Jenkins and can be installed by simply clicking on them.
Jenkins provides more than 300 plugins to support building, deploying, and automating any type of project from scratch to production including Java, Javascript, PHP, Ruby, Android and others.
It also has its own REST API, so you can create your own custom tools that integrate with Jenkins without needing to know how to code or anything about Jenkins’ architecture internals.
You are a sysadmin looking for a solution that will help you save time while deploying small applications to your machines. After looking at some options, you come across Jenkins, which claims to be able to solve all your problems. You dive in, read the documentation and install Jenkins. The documentation guides you through the installation process, but you can not quite get it installed correctly.
Installing and configuring the necessary software components for a complete, working build system is not as easy as it may sound. That’s why we created this step-by-step tutorial on how to install and configure Jenkins on AlmaLinux 8.
Prerequisites
In order to install Jenkins on AlmaLinux 8, you will need:
- A 64-bit AlmaLinux 8 machine with a working Internet connection.
- Root access to your server. You can get it by following this guide.
- System Requirements: according to the Jenkins official website, a basic installation of Jenkins needs a minimum 2 GB of RAM. Jenkin requires 50 GB of free disk space for the installation, plus 1 GB of free disk space for each build slave you want to add. In addition, you will need one CPU core and one GB of RAM per concurrent build worker that you expect to support.
Updating Your System
Before you get started with installing and configuring Jenkins, you should update your system to the latest available version of the software packages.
For that, ssh to your server and run the following command. The epel-release package provides updated packages from the Extras development repository which are not yet part of a major RHEL release. The Extras repo contains packages that are not included in Red Hat’s standard set of packages but are nevertheless built for RHEL releases. This includes language packs, support for newer versions of adaptive icons, and other functionality updates.
- sudo dnf check-update && sudo dnf update -y
- sudo dnf install epel-release
Installing Java
Java is a programming language that is based on C. It’s considered to be one of the most popular programming languages because it has been used in many software such as Android and Google Chrome. Java is a cross-platform programming language that can run autonomous applications on both Windows and Linux operating systems, as well as MacOS, Solaris, FreeBSD, and other UNIX systems.
Jenkins, at its core, is a Java program that requires you install the Java Runtime Environment (JRE) and the Java Development Kit (JDK) on your system in order to function properly.
This demo will install the OpenJDK 11 on the system. The OpenJDK is a free and open-source implementation of the Java Platform, Standard Edition (Java SE). It is a development and runtime environment for building applications, microservices, and other server systems that run on the Java virtual machine (JVM).
The OpenJDK is based on the Oracle’s Java Development Kit version 8 with Project Jigsaw support. This means you can run Jenkins in OpenJDK 11 with Project Jigsaw without any compatibility issues.
Run the following command to install OpenJDK 11 on your system.
sudo dnf install java-11-openjdk -y
Once the installation is complete, you can run the command to check if it’s working correctly.
java -version
You will see the following output.
Installing Jenkins
Now that you have Java installed, you’re ready to install Jenkins.
The AlmaLinux base repository does not include any of the Jenkins packages, so first, you will need to add the official repository from its developer. It’s the only repository allowed to distribute software packaged for a specific supported distribution. In this case, it’s the Jenkins developer’s own repository for Redhat and its derivatives.
Run the following command to import the Jenkins key to the system. This key is a security mechanism used to validate the authenticity of a software package.
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
Run the following command to add the Jenkins repository to the system.
cd /etc/yum.repos.d/ && curl -O https://pkg.jenkins.io/redhat-stable/jenkins.repo
Run the sudo dnf makecache command to refresh the metadata cache of all enabled repositories to ensure that local disk repository data is up to date. This can be used when updating/installing packages or if the metadata has been corrupted.
sudo dnf makecache
Run the following command to verify if the Jenkins repository has been added to your syste. It is a way to check on the current list of repositories, which indicates to the package manager which repositories have been enabled. In other words, it is a way to see which repositories are currently being tracked by dnf.
sudo dnf repolist
Run the following command to install Jenkins on your system.
dnf install -y jenkins
Once the command has finished installing, run the following command to start the Jenkins service.
sudo systemctl start jenkins
Run the following command to check the status of the Jenkins service.
sudo systemctl status jenkins
Jenkins is a continuous integration service that can monitor executions of repeated jobs, such as building a software project or jobs run by cron. Monitoring the status of Jenkins can help us know whether they are running as expected. This knowledge may be helpful in troubleshooting any issues with jobs that it runs that are not successful.
You will see the following output.
Configuring Your Firewall
Jenkins is your automated build server, it helps with continuous integration and deployment for your projects. Jenkins has the ability to allow SSH connections to perform builds and tasks on remote slave nodes. However, you will need to configure your firewall to allow Jenkins access to these servers.
You will need to open port 22 (SSH) and optionally port 8080 (Web client) for Jenkins to be able to connect to the remote servers your applications reside on. These ports are usually closed by default when using cloud-based virtual machines. If you are setting up Jenkins on your own hardware, you will need to allow these ports through your firewall or router.
Run the following command to open these ports on your firewall.
sudo firewall-cmd --permanent --zone=public --add-port=22/tcp
sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp
Run the following command to apply your changes. The sudo firewalld –reload command ensures that the rules and configurations currently in force will be reloaded if present. This can be useful to apply changes made through the firewall-cmd tools to the running system.
sudo firewall-cmd --reload
Finally, run the following command to check if the rules have been added successfully.
sudo firewall-cmd --list-all
Accessing Jenkins Web UI
Now that you have your Jenkins server up and running but you want to access it in the web browser. You can access Jenkins by visiting its IP address on port 8080.
For example, if your IP is 192.168.1.100 and the default port is 8080, then navigate the following address to go to Jenkins: 192.168.1.100:8080
When you try to access the Jenkins web UI, you will get an Unlock Jenkins screen asking you to go to /var/lib/jenkins/secrets/initialAdminPassword, as shown below. This is encrypted data that contains the password you used to log in to the dashboard. It stores the initialAdminPassword in an encrypted form. This ensures that a malicious user who has gained access to your Jenkins server does not have the password that you used on first login.
Return back to your terminal, where you should be still logged in as the root user. Enter the following command to decrypt it:
cat /var/lib/jenkins/secrets/initialAdminPassword
You will see the output that contains the password to the Jenkins web UI.
Copy and paste this into your favorite editor and save it somewhere on your machine. You can now use this password to access your Jenkins web interface.
On the next screen, select install suggested plugins. A plugin is nothing more than a directory with some files in it. When you install the plugin, Jenkins detects the directory and enables the features that are specified in the files.
When you first install Jenkins, you should choose the option to install suggested plugins. This option installs all of the plugins that are needed for a basic Jenkins setup. No worries, you can always change or add more plugins later in the Plugins section of the web interface.
On the Create First Admin User screen, provide your username, E-mail address, full name, and password. Click on Save and continue to go to the next screen.
On the next screen, keep the default and click on Start using Jenkins
You will be taken to the Jenkins dashboard, as shown below. When you first installed Jenkins, it probably came with a blank page as a default page. You can see this if you look at the source of the page – there’s nothing there.
However, over time, as you start adding jobs and plugins, the page will transform into a dashboard that displays visual information about your projects.
Conclusion
In this post, you learned how to install and configure a Jenkins server. This is only the beginning, however; it is a very valuable automated build environment that can be leveraged in your daily practice. Leave your comments and suggestions in the section below if you have any feedback or questions.