How to install and set up Jenkins in Rocky Linux/Centos 8

In this Guide we are going to learn how to install and configure Jenkins in Rocky Linux/Centos 8. This will also work for other RHEL 8 derivatives like Alma Linux.

Jenkins is a popular opensource automation tool to perform continuous integration and build automation. Jenkins allows to execute a predefined list of steps, e.g. to compile golang source code to build build binary file. The trigger for this execution can be time or event based.

Possible steps executed by Jenkins are for example:

  • Cloning the code from source control system.
  • execute a command to install dependencies required for the code to run
  • Run tests for the software
  • build the software to get an executable
  • Publish test results
  • publish the resulting binary code

Jenkins monitors the execution of the steps and allows to stop the process, if one of the steps fails. Jenkins can also send out notifications in case of a build success or failure.

Jenkins can be extended by additional plug-ins. For example, you can install plug-ins to support building and testing Android applications.

Requirements

  • A Linux system with Rocky Linux/CentOS 8 server (At least 2GB of Ram)
  • A user account with sudo or root privileges
  • Access to a terminal window/command line
  • Recent Java version installed

Table of content

  1. Ensuring that the system is up to date
  2. Install Java
  3. Install Jenkins
  4. Starting and enabling jenkins
  5. Accessing Jenkins
  6. Optional – Using an Ansible playbook

1. Ensuring that the system is up to date

Ensure that the system packages are up to date using this command:

sudo dnf -y update

Next, let us install common packages that we will need in our tutorial

sudo dnf install -y curl vim wget

2. Install Java

In this section, we will install java on our system. We will be using the openjdk version of java. In Rocky Linux 8, to check what software provides the java command line, use the following command to search dnf search jdk. Since Jenkins uses Java version 11, we cann filter the result using grep.

# dnf search jdk | grep 11
Last metadata expiration check: 0:03:42 ago on Wed 24 Nov 2021 06:10:29 AM EAT.
java-11-openjdk.x86_64 : OpenJDK 11 Runtime Environment
java-11-openjdk-demo.x86_64 : OpenJDK 11 Demos
java-11-openjdk-devel.x86_64 : OpenJDK 11 Development Environment
java-11-openjdk-headless.x86_64 : OpenJDK 11 Headless Runtime Environment
java-11-openjdk-javadoc.x86_64 : OpenJDK 11 API documentation
java-11-openjdk-javadoc-zip.x86_64 : OpenJDK 11 API documentation compressed in a single archive
java-11-openjdk-jmods.x86_64 : JMods for OpenJDK 11
java-11-openjdk-src.x86_64 : OpenJDK 11 Source Bundle
java-11-openjdk-static-libs.x86_64 : OpenJDK 11 libraries for static linking

We can see that it is jdk 11 is available as

java-11-openjdk. Install it using the command

sudo dnf install -y <meta charset="utf-8">java-11-openjdk

Confirm the installed version using this command:

$ java -version
openjdk version "11.0.13" 2021-10-19 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.13+8-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.13+8-LTS, mixed mode, sharing)

3. Install Jenkins

Add jenkins repository

Jenkins isn’t included in the default CentOS software repositories. Use the following commands to add and import the GPG key to ensure your software is legitimate.

sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

Install jenkins

If its not yet installed, please use this command to install epel-release. This repo contains some dependencies that our jenkins server needs like daemonize.

sudo dnf install epel-release

Use the following command to install jenkins

sudo dnf install jenkins

4. Starting and enabling jenkins

Now that jenkins is installed, let us start it using this command:

sudo systemctl start jenkins

To display the status of the Jenkins service, enter the following:

$ sudo systemctl status jenkins
● jenkins.service - LSB: Jenkins Automation Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins; generated)
   Active: active (running) since Wed 2021-11-24 06:23:59 EAT; 4s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 64639 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=0/SUCCESS)
    Tasks: 37 (limit: 23168)
   Memory: 241.4M
   CGroup: /system.slice/jenkins.service
           └─64645 /etc/alternatives/java -Djava.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins ->

Nov 24 06:23:59 cloudsrv.citizix.com systemd[1]: Starting LSB: Jenkins Automation Server...
Nov 24 06:23:59 cloudsrv.citizix.com jenkins[64639]: Starting Jenkins [  OK  ]
Nov 24 06:23:59 cloudsrv.citizix.com systemd[1]: Started LSB: Jenkins Automation Server.

Please check to ensure that the status is active (running) to know that the installation was successful.

To enable Jenkins on boot, use this:

sudo systemctl enable jenkins

5. Accessing the jenkins server

Once installed, open browser and navigate to the jenkins on the url http://127.0.0.1:8080/. If you are running on a remote server, replace the ip 127.0.0.1 with that server’s ip.

You will be asked to provide an initial password found in this location /var/lib/jenkins/secrets/initialAdminPassword. Get it by running this command on the server.

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

Citizix - Jenkins install unlock

Citizix – Jenkins install unlock

From here choose whether you want to install the recommended plugins or choose what you want to install.

Citizix - Cuztomize jenkins

Citizix – Cuztomize jenkins

The last page will allow you to set up some initial configuation for the user who will be using the jenkins server.

Citizix - Jenkins Create First Admin User

Citizix – Jenkins Create First Admin User

6. Optional – Using an Ansible playbook

You can use the following playbook to accomplish the same task. Save it to a file like install-jenkins.yaml.
To run the playbook:

  • Ensure ansible is installed. Checkout guide on how to install here.
  • Create a hosts file with connection information
  • Run the command ansible-playbook -i <hosts-file-path> install-jenkins.yaml -vvv
- name: Install jenkins on centos 8
  hosts: jenkins-srv
  become: yes
  gather_facts: False
  tasks:
      - name: Install required packages
        dnf:
          name:
            - wget
          state: latest

      - name: Install java
        dnf:
          name: java-1.8.0-openjdk-1:1.8.0.275.b01-1.el8_3.x86_64
          state: latest

      - name: Add jenkins repository
        shell: |
          wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
          rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
        args:
          warn: no

      - name: Install jenkins
        dnf:
          name: jenkins
          state: latest

      - name: Start jenkins service
        systemd:
          name: jenkins
          state: started

      - name: Enable jenkins service
        systemd:
          name: jenkins
          enabled: yes

Conclusion

We managed to install Jenkins in Rocky Linux server in this guide.

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy