Red Hat DevOps Pipelines and Processes: CI/CD with Jenkins, Git, and Test Driven Development/Ch 1. Introduction to DevOps Pipelines and CI/CD on OpenShift

Chapter 1

Introduction to DevOps Pipelines and CI/CD on OpenShift

0:00
1x

Chapter Summary

# Chapter 1: Introduction to DevOps Pipelines and CI/CD on OpenShift Welcome to the first step in mastering modern software delivery within the Red Hat ecosystem. If you are reading this, you likely understand that software is no longer a product delivered once a year on a physical disk; it is a li...

Chapter 1: Introduction to DevOps Pipelines and CI/CD on OpenShift

Welcome to the first step in mastering modern software delivery within the Red Hat ecosystem. If you are reading this, you likely understand that software is no longer a product delivered once a year on a physical disk; it is a living service that must evolve daily.

In this chapter, we will define the core philosophy of DevOps pipelines and explore why Red Hat OpenShift provides the ideal environment for Continuous Integration and Continuous Delivery (CI/CD). We will move beyond the buzzwords to look at the mechanics of how code travels from a developer’s workstation to a production-ready container.


1.1 The Shift from "Big Bang" to Continuous

In traditional IT environments, software releases were "events." They involved "war rooms," weekend-long deployment windows, and a significant amount of manual configuration. This approach—often called the "Big Bang" release—is inherently risky because the delta (the amount of change) between the current version and the new version is massive.

DevOps changes this by advocating for small, frequent changes. By automating the path to production, we reduce the "blast radius" of any single failure and increase the speed at which we can deliver value to users.

The DevOps Pipeline as an Assembly Line

Think of a DevOps pipeline as an automated assembly line in a car factory. In the old days, a mechanic might build a whole car by hand (manual deployment). In a modern factory, the chassis moves along a belt. At each station, a specific robot performs a task: one welds a door, another paints a panel, and another tests the engine. If any robot fails its task, the belt stops immediately.

In our world, the "chassis" is your source code, and the "robots" are your Jenkins stages, unit tests, and OpenShift build processes.

Key Insight: A pipeline is not just about speed; it is about predictability. The goal of CI/CD is to ensure that every version of your software is built, tested, and deployed in exactly the same way every single time.


1.2 Defining CI, CD, and Continuous Deployment

While often grouped together, CI and CD represent distinct stages of the lifecycle.

Continuous Integration (CI)

CI is the practice of merging all developer working copies to a shared mainline (usually the

text
main
or
text
master
branch in Git) several times a day.

  • The Goal: Find bugs early.
  • The Process: Every time you push code, an automated build and test suite runs. If the build fails, the team is notified immediately.

Continuous Delivery (CD)

CD is the practice of ensuring that your code is always in a releasable state.

  • The Goal: Push-button deployments.
  • The Process: After passing CI, the code is automatically deployed to a "Staging" or "UAT" (User Acceptance Testing) environment. The decision to push to "Production" remains a human one.

Continuous Deployment

This is the final evolution. In this model, every change that passes all stages of your automated pipeline is released directly to production without human intervention. This requires a high degree of confidence in your automated testing suite (TDD).


1.3 Why OpenShift for CI/CD?

You might ask, "Why can't I just run Jenkins on a standalone Linux server?" While you could, Red Hat OpenShift (enterprise-grade Kubernetes) provides several "superpowers" for DevOps:

  1. Environment Parity: OpenShift ensures that your Development, Testing, and Production environments are identical. If it works in a container on Dev, it will work in a container on Prod.
  2. Self-Healing: If a deployment fails or a pod crashes, OpenShift automatically restarts it or rolls back to the previous version.
  3. Integrated Registry: OpenShift includes a built-in container image registry, making it easy to store and manage the images created by your pipeline.
  4. Resource Quotas: You can ensure that your CI/CD builds don't starve your production applications of CPU and memory.

Real-World Example: The "BankSyc" Scenario

Imagine a financial services company, BankSyc. They have a legacy monolithic application that takes six months to update. By moving to OpenShift and implementing a Jenkins-based pipeline, they split the monolith into microservices. Now, the "Currency Exchange" team can update their service three times a day without affecting the "Savings Account" team. This is the power of containerized CI/CD.


1.4 Anatomy of an OpenShift-Native Pipeline

An intermediate-level pipeline on OpenShift typically involves four main components:

  1. Git (The Source of Truth): Where the code and configuration reside.
  2. Jenkins (The Orchestrator): The engine that executes the pipeline steps.
  3. S2I (Source-to-Image): A tool within OpenShift that takes source code, injects it into a base image, and creates a ready-to-run container.
  4. OpenShift Objects: DeploymentConfigs, Services, and Routes that define how the app runs.

Example: A Simple Jenkinsfile

A

text
Jenkinsfile
is a text file that contains the definition of a Jenkins Pipeline and is checked into source control. Here is a basic example of what an OpenShift-centric pipeline looks like:

groovy
pipeline {
    agent {
        label 'maven' // Uses a specialized Jenkins agent with Maven installed
    }
    stages {
        stage('Checkout') {
            steps {
                git url: 'https://github.com/example/my-openshift-app.git'
            }
        }
        stage('Build & Test') {
            steps {
                sh 'mvn clean package' // Test Driven Development happens here
            }
        }
        stage('OpenShift Build') {
            steps {
                script {
                    // Start a build in OpenShift using the S2I strategy
                    openshift.withCluster() {
                        openshift.withProject() {
                            openshift.selector("bc", "my-app").startBuild()
                        }
                    }
                }
            }
        }
        stage('Deploy to Dev') {
            steps {
                script {
                    openshift.withCluster() {
                        openshift.withProject() {
                            // Trigger the deployment
                            openshift.selector("dc", "my-app").rollout().latest()
                        }
                    }
                }
            }
        }
    }
}

1.5 Best Practices for DevOps Pipelines

To succeed at an intermediate level, you must move beyond just "making it work." You must make it robust.

1. Build Once, Deploy Everywhere

Never rebuild your code for different environments. Your pipeline should build a container image once, tag it (e.g.,

text
v1.2.3
), and push it to the registry. That same image should then be promoted through Dev, QA, and Prod. This ensures that what you tested is exactly what you are running in production.

2. Shift Left on Security

Security shouldn't be an afterthought at the end of the pipeline. Integrate container scanning (like Red Hat Advanced Cluster Security) and static code analysis early in the process.

  • Tip: If a high-severity vulnerability is found in a library during the "Build" stage, fail the pipeline immediately.

3. Use Trunk-Based Development

Avoid long-lived feature branches. The longer a branch exists away from the

text
main
branch, the harder the "Merge Hell" will be. Encourage developers to merge small changes into the main trunk daily.

4. Treat Infrastructure as Code (IaC)

Your OpenShift configurations (YAML files for Services, Routes, and Deployments) should be stored in Git right alongside your application code. This practice is known as GitOps.


1.6 Summary and Moving Forward

In this chapter, we established that a DevOps pipeline is the mechanical backbone of modern software delivery. We explored how OpenShift acts as a robust platform for these pipelines, providing the scalability and consistency that traditional servers lack.

Practical Tip: As you progress through this book, don't just copy-paste the code. Try to "break" the pipeline. Delete a service in OpenShift and see how the pipeline reacts. Purposefully fail a unit test to ensure the pipeline stops. Understanding how a pipeline fails is just as important as understanding how it succeeds.

In the next chapter, we will dive deep into Git Workflows, exploring how to structure your repositories to support complex, multi-team environments.


Check Your Knowledge

  1. What is the primary difference between Continuous Delivery and Continuous Deployment?
  2. Why is "Build Once, Deploy Everywhere" a critical rule in containerized pipelines?
  3. In the provided Jenkinsfile, why do we use a specific
    text
    agent { label 'maven' }
    instead of a generic one?

Word Count: ~1,150 words

What You Learned

  • 1

    DevOps pipelines facilitate continuous delivery of software by enabling small, frequent changes that minimize risk and enhance speed.

  • 2

    OpenShift offers an optimal environment for implementing CI/CD practices, automating code deployment from development to production.

  • 3

    Transitioning from traditional 'Big Bang' releases to a DevOps pipeline approach significantly reduces the complexity and potential failures during software deployment.

📖 Key Terms

CI/CD

CI/CD stands for Continuous Integration and Continuous Deployment, a set of practices aimed at automating the integration and deployment of code changes.

OpenShift

OpenShift is a cloud-based platform for developing, deploying, and managing applications, built on Kubernetes.

DeploymentConfig

In OpenShift, DeploymentConfig is a resource used to describe how a deployment should occur, managing the deployment and scaling of applications.

Jenkins

Jenkins is an open-source automation server widely used for implementing CI/CD processes by facilitating the building, testing, and deploying of applications.

Automated Testing

Automated Testing refers to the use of software tools to run tests on code changes automatically, ensuring quality and functionality before deployment.

Quiz requires login

Sign in to take the quiz and track your progress.