Thursday, May 1, 2025

Setting Up a CI/CD Pipeline with Jenkins on RHEL9: A Step-by-Step Guide

 

Introduction

In the fast-paced world of software development, Continuous Integration (CI) and Continuous Delivery (CD) have become essential practices for ensuring the reliability and efficiency of code deployment. Jenkins, an open-source automation server, plays a crucial role in setting up robust CI/CD pipelines. In this guide, we’ll walk you through the process of setting up a CI/CD pipeline using Jenkins on Red Hat Enterprise Linux 9 (RHEL 9). Follow these step-by-step instructions to streamline your development and deployment workflows.

CI/CD with Jenkins on RHEL9

Photo by Tom Fisk from Pexels.com

Prerequisites

Before diving into the installation and configuration, make sure you have the following prerequisites in place:

  1. A running instance of RHEL 9 with administrative privileges.
  2. A stable internet connection for downloading necessary packages.

CI/CD with Jenkins on RHEL9

Begin by updating your system and installing Java Development Kit (JDK). Jenkins is built on Java, so this step is crucial.

$ sudo dnf update
$ sudo dnf install java-11-openjdk-devel

Now, download and install the Jenkins repository key and enable the Jenkins repository:

$ 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:

$ sudo dnf install jenkins

Start and enable Jenkins service:

$ sudo systemctl start jenkins
$ sudo systemctl enable jenkins

Step 1: Configure Jenkins:

Access Jenkins through your web browser by navigating to http://<your-server-IP>:8080. Retrieve the initial administrator password using:

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

Follow the on-screen instructions to complete the Jenkins setup.

Step 2: Install Required Plugins

Once Jenkins is up and running, install the necessary plugins to support your CI/CD workflow. Common plugins include Git, GitHub, Docker, and Pipeline.

  1. Navigate to Jenkins dashboard.
  2. Click on “Manage Jenkins” > “Manage Plugins.”
  3. Go to the “Available” tab, search for the required plugins, and install them.

Step 3: Create a New Jenkins Job

  1. Click on “New Item” on the Jenkins dashboard.
  2. Enter a job name and select the type of project (freestyle project or pipeline).
  3. Configure the job with your source code repository, build triggers, and other settings.

CI/CD with Jenkins on RHEL9: Configuration

Step 4: Configure CI/CD Pipeline Script

If you chose the Pipeline job type, you’ll need to define your CI/CD pipeline using the Jenkinsfile. Here’s a basic example:

pipeline {
    agent any
    stages {
        stage('Checkout') {
            steps {
                checkout scm
            }
        }
        stage('Build') {
            steps {
                // Your build commands
            }
        }
        stage('Test') {
            steps {
                // Your testing commands
            }
        }
        stage('Deploy') {
            steps {
                // Your deployment commands
            }
        }
    }
}

Customize the stages based on your project’s requirements.

Step 5: Save and Run Your Jenkins Job

Save your Jenkins job configuration and trigger a manual build or wait for the defined triggers to start the CI/CD pipeline.

No comments:

Post a Comment

HTTP Appache Server LAB 7

 Apache HTTP Server (httpd) Configuration,