CentLinux | Learn How to Install CentOS/Rocky Linux Servers

Wednesday, November 2, 2022

How to install Jenkins on Rocky Linux 9

In this configuration guide, you will learn how to install Jenkins on Rocky Linux 9 or other RPM based Linux distros.

 

Table of Contents:

 

What is CI/CD?:

In DevOps practices, the automated process of building, testing and delivering is called CI/CD (Continuous Integration / Continuous Delivery) pipeline.

  • CI (Continuous integration) is a practice in which team members regularly commits their code changes to the version control repository (such as git or svn), after which automated builds and tests are performed using build tools (such as Apache Ant, Apache Maven, Gradle, Junit, etc).
  • CD (Continuous delivery) is a series of practices where code changes are automatically built, tested and deployed to production.

 

What is Jenkins?:

Jenkins is an open source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery. It is a server-based system that runs in servlet containers such as Apache Tomcat. It supports version control tools, including AccuRev, CVS, Subversion, Git, Mercurial, Perforce, ClearCase and RTC, and can execute Apache Ant, Apache Maven and sbt based projects as well as arbitrary shell scripts and Windows batch commands. (Source: Wikipedia)

Plugins have been released for Jenkins that extend its use to projects written in languages other than Java. Plugins are available for integrating Jenkins with most version control systems and bug databases. Many build tools are supported via their respective plugins. Plugins can also change the way Jenkins looks or add new functionality. There are a set of plugins dedicated for the purpose of unit testing that generate test reports in various formats (for example, JUnit bundled with Jenkins, MSTest, NUnit, etc.) and automated testing that supports automated tests. Builds can generate test reports in various formats supported by plugins (JUnit support is currently bundled) and Jenkins can display the reports and generate trends and render them in the GUI.


Read Also:


Environment Specification:

We are using a minimal Rocky Linux 9 virtual machine with following specifications.

  • CPU - 3.4 Ghz (2 cores)
  • Memory - 2 GB
  • Storage - 20 GB
  • Operating System - Rocky Linux release 9.0 (Blue Onyx)
  • Hostname - jenkins-01.centlinux.com
  • IP Address - 192.168.116.131/24

 

Updating Linux Operating System:

Connect with your Rocky Linux 9 server as root user by means of a ssh client.

Set a meaningful FQDN (Fully Qualified Domain Name) for your Linux machine by executing hostnamectl command.

# hostnamectl set-hostname jenkins-01.centlinux.com

Rebuild cache of your yum package manager.

# dnf makecache --refresh
Rocky Linux 9 - BaseOS                          105 kB/s | 1.7 MB     00:16
Rocky Linux 9 - AppStream                       354 kB/s | 6.0 MB     00:17
Rocky Linux 9 - Extras                          873  B/s | 2.9 kB     00:03
Metadata cache created.

Execute following command to update your Rocky Linux operating system.

# dnf upgrade -y

Sometimes, the above command also updates Linux Kernel. In this case, you should reboot your Linux operating system before moving forward.

# reboot

After reboot, verify the Operating system and Kernel versions.

# cat /etc/rocky-release
Rocky Linux release 9.0 (Blue Onyx)

# uname -r
5.14.0-70.26.1.el9_0.x86_64

 

Installing OpenJDK Java 11:

Jenkins is a Java application, thus it requires Java Virtual Machine (JVM) for execution.

Jenkins 2.3 is current stable version and it requires Java 11.

Luckily, OpenJDK Java 11 is available in standard yum repositories. Therefore, you can easily install it by using dnf command.

# dnf install -y java-11-openjdk-devel java-11-openjdk

After successful installation, verify the version of active Java on your Linux platform.

# java --version
openjdk 11.0.17 2022-10-18 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.17.0.8-2.el9_0) (build 11.0.17+8-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.17.0.8-2.el9_0) (build 11.0.17+8-LTS, mixed mode, sharing)

 

Installing Jenkins:

Jenkins can be install in three ways.

  1. Individual RPM: Individual RPMs are available for every version of Jenkins, but one has to resolve dependencies manually.
  2. Jenkins yum Repository: A Yum repository is provided for Jenkins packages. Here, dependent packages will be installed automatically.
  3. Generic Web Archive: This Java web archive requires to be executed either using java command or should be deployed on a Jave EE Server (e.g Apache Tomcat) to work.

We prefer to use Jenkins yum repository, because, it is quite simple to understand and in this method software dependencies will be resolved automatically.

You will need wget command to download Jenkins official yum repository. Therefore, install it now.

# dnf install -y wget

By using wget command, download Jenkins yum repository into /etc/yum.repos.d directory.

# wget https://pkg.jenkins.io/redhat-stable/jenkins.repo -O /etc/yum.repos.d/jenkins.repo
--2022-10-31 11:29:47--  https://pkg.jenkins.io/redhat-stable/jenkins.repo
Resolving pkg.jenkins.io (pkg.jenkins.io)... 199.232.46.133, 2a04:4e42:48::645
Connecting to pkg.jenkins.io (pkg.jenkins.io)|199.232.46.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 85
Saving to: ‘/etc/yum.repos.d/jenkins.repo’

/etc/yum.repos.d/je 100%[===================>]      85  --.-KB/s    in 0s

2022-10-31 11:29:49 (3.94 MB/s) - ‘/etc/yum.repos.d/jenkins.repo’ saved [85/85]

Import the GPG Key of Jenkins yum repository.

# rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

Build the yum cache for recently added repositories.

# dnf makecache
Jenkins-stable                                  5.7 kB/s |  24 kB     00:04
Rocky Linux 9 - BaseOS                          1.1 kB/s | 3.6 kB     00:03
Rocky Linux 9 - AppStream                       2.0 kB/s | 3.6 kB     00:01
Rocky Linux 9 - Extras                          1.4 kB/s | 2.9 kB     00:02
Metadata cache created.

Now, you can easily install Jenkins by invoking dnf command.

# dnf install -y jenkins
Last metadata expiration check: 0:00:28 ago on Mon 31 Oct 2022 11:30:49 AM CDT.
Dependencies resolved.
================================================================================
 Package          Architecture    Version                Repository        Size
================================================================================
Installing:
 jenkins          noarch          2.361.2-1.1            jenkins           89 M

Transaction Summary
================================================================================
Install  1 Package

Total download size: 89 M
Installed size: 89 M
Downloading Packages:
jenkins-jenkins-2.361.2-1.1.  0% [                    ] ---  B/s |   0  B     --jenkins-2.361.2-1.1.noarch.rpm                  616 kB/s |  89 MB     02:27
--------------------------------------------------------------------------------
Total                                           616 kB/s |  89 MB     02:27
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Running scriptlet: jenkins-2.361.2-1.1.noarch                             1/1
  Installing       : jenkins-2.361.2-1.1.noarch                             1/1
  Running scriptlet: jenkins-2.361.2-1.1.noarch                             1/1
  Verifying        : jenkins-2.361.2-1.1.noarch                             1/1

Installed:
  jenkins-2.361.2-1.1.noarch

Complete!

 

Configuring Systemd Service:

Enable and start the Jenkins service.

# systemctl enable --now jenkins.service
Created symlink /etc/systemd/system/multi-user.target.wants/jenkins.service → /usr/lib/systemd/system/jenkins.service.

Verify the status of Jenkins service.

# systemctl status jenkins.service
● jenkins.service - Jenkins Continuous Integration Server
     Loaded: loaded (/usr/lib/systemd/system/jenkins.service; enabled; vendor p>
     Active: active (running) since Mon 2022-10-31 11:36:53 CDT; 8s ago
   Main PID: 2260 (java)
      Tasks: 43 (limit: 5736)
     Memory: 338.7M
        CPU: 1min 48.907s
     CGroup: /system.slice/jenkins.service
             └─2260 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java>

Oct 31 11:36:53 jenkins-01.centlinux.com systemd[1]: Started Jenkins Continuous>
Oct 31 11:36:55 jenkins-01.centlinux.com jenkins[2260]: 2022-10-31 16:36:55.032>

 

Configure Linux Firewall:

Jenkins default service port is 8080/tcp. Therefore, you need to allow this port in Linux Firewall to make you Jenkins server accessible from the network.

Use firewall-cmd command to allow Jenkins service port in Linux firewall.

# firewall-cmd --permanent --add-port=8080/tcp
success

# firewall-cmd --reload
success

 

Accessing Jenkins Web Interface:

To access Jenkins web interface, open URL http://jenkins-01.centlinux.com:8080 in a web browser.

You can obtain the auto-generated password from the file, that was mentioned in above image.

# cat /var/lib/jenkins/secrets/initialAdminPassword

Enter the auto-generated password and click on "Continue".

Jenkins setup is now asking for installing Plugins. You can either choose your required plugins or install suggested plugins.

Click on "Install suggested plugins".

Jenkins setup is now installing commonly used plugins for your CI/CD software.

After installing plugins, Jenkins setup is now giving you the option to create an Admin user.

However, you can skip user creation and use the default admin user. But we strongly recommend that, you should create a custom admin user to improve security for your Jenkins web interface.

Verify the auto-generated Jenkins URL and click on "Save and Finish".

Jenkins setup has been completed. Click on "Start using Jenkins".

You have reached at the Dashboard of your Jenkins web interface.

 

Conclusion:

In this configuration guide, you have successfully learned how to install Jenkins on Rocky Linux 9 or other RPM based Linux distros.

If you find this article useful? Consider supporting us by Buy Me A Coffee


2 comments:

  1. [root@localhost jenkins]# update-alternatives --config java

    There is 2 program that provides 'java'.

    Selection Command
    -----------------------------------------------
    *+ 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.372.b07-1.el8_7.x86_64/jre/bin/java)
    2 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.19.0.7-1.el8_7.x86_64/bin/java)

    Enter to keep the current selection[+], or type selection number: 2
    [root@localhost jenkins]#

    ReplyDelete
    Replies
    1. It looks like, you are not installing on a minimal Linux OS. No problem, if you have multiple Java installations you can always use update-alternatives or alternatives command to select your preferred version.

      Delete

© 2023 CentLinux. All Rights Reserved.