Hello! Welcome to the next lesson in our final module, Containerization and CI/CD.
In our last session, you mastered the hands-on process of transforming your Spring Boot application into a portable Docker image and running it as an isolated container. You manually executed docker build and docker run, giving you full control over the process. This is a vital skill, but what if these steps could be automated, secure, and repeatable for every code change you make?
This brings us to today's topic. This lesson addresses the learning outcome: Describe the concepts and stages of a CI/CD pipeline (Continuous Integration/Continuous Deployment). We will explore the principles and structure behind the automated workflows that are the backbone of modern software development. You will learn how CI/CD pipelines solve the challenges of manual deployments and enable teams to deliver high-quality software faster and more reliably.
1. The Problem With Manual Deployments
Before diving into what a CI/CD pipeline is, it's essential to understand the problems it solves. Imagine a team working without automation. The end of a development cycle is often fraught with challenges: developers rush to merge weeks of work, leading to complex merge conflicts. Tests are run late in the process, uncovering a tangled mess of bugs that are difficult to trace. The deployment itself is a stressful, manual procedure, prone to human error and often reserved for senior engineers.
To get a vivid picture of this scenario, let's watch the beginning of a video from the "TechWorld with Nana" channel.
CI/CD Explained: The DevOps Skill That Makes You 10x More Valuable
This video, titled 'CI/CD Explained', opens with a compelling story of a problematic manual deployment process. It perfectly illustrates the pain points that CI/CD is designed to eliminate.
Watch from 00:15 to 03:40. Pay attention to the issues mentioned, such as merge conflicts, late bug discovery, manual testing, code freezes, and the anxiety surrounding production releases.
As the video highlights, a manual process is constrained by human limitations—it's time-consuming, error-prone, and stressful. CI/CD offers a systematic, automated solution to these problems.
2. The Core Concepts: CI, Continuous Delivery, and Continuous Deployment
CI/CD is an umbrella term for a set of practices that automate the software delivery lifecycle. It's composed of two main parts, with the "CD" having two different interpretations.

Continuous Integration (CI)
Continuous Integration is the practice where developers frequently merge their code changes into a central repository (like your GitHub repository). After each merge, an automated process kicks in to build the application and run a suite of automated tests.
The primary goal of CI is to detect integration issues as early as possible. Instead of waiting until the end of a sprint to combine everyone's work, small changes are integrated and verified continuously.
CI/CD Explained: The DevOps Skill That Makes You 10x More Valuable
The 'CI/CD Explained' video provides a clear explanation of how Continuous Integration works.
Please watch from 03:40 to 06:31. Notice how the focus shifts from testing large, infrequent merges to testing small, frequent commits, which helps isolate and fix bugs much faster.
Continuous Delivery vs. Continuous Deployment (CD)
Both "Continuous Delivery" and "Continuous Deployment" are abbreviated as CD and handle the release process after a change successfully passes the CI stage. However, they differ in one critical aspect: the final deployment to production.
To understand the precise distinction between these two concepts, let's read a short section from the Palo Alto Networks article, 'What Is the CI/CD Pipeline?'.
Please read the subsections titled 'Continuous Delivery and Deployment (CD)' and 'Continuous Delivery Vs. Continuous Deployment'. Focus on the key difference regarding the final deployment step.
To summarize the distinction:
- Continuous Delivery: The release process is automated all the way to the production environment, but the final step to deploy to live users requires manual approval. This could be a one-click button press by a product manager or team lead. The software is always in a deployable state, but a human makes the final "go" decision.
- Continuous Deployment: This practice goes one step further. Every change that passes all automated tests is automatically deployed to production without any human intervention. This requires a high degree of confidence in the automated test suite.
For the rest of this course, when we refer to a CI/CD pipeline, we will primarily be building towards Continuous Delivery, which is a more common and safer starting point for most projects.
3. The Stages of a CI/CD Pipeline
A CI/CD pipeline is a series of automated stages that your code flows through from commit to deployment. While pipelines can vary in complexity, they typically consist of four main stages: Source, Build, Test, and Deploy.
How to design a modern CI/CD Pipeline
Let's watch a video from the 'DevOps Journey' channel that walks through the design of a modern pipeline, detailing what happens in each stage.
Watch from 00:32 to 09:08. The video breaks down the pipeline into four key stages: Source, Build, Test, and Release (Deploy). Pay attention to the specific activities performed in each stage, such as linting, compiling, running unit tests, and creating container images.
Let's recap and consolidate the information from the video and our other resources.
Stage 1: Source
This is the trigger for the entire pipeline. It starts when a developer commits code to the version control system.
- Action:
git pushto a repository (e.g., on GitHub). - Activities: The CI server (e.g., GitHub Actions, Jenkins) detects the push and starts the pipeline. This stage can also include preliminary checks like linting (checking for code style errors) and ensuring pull request (PR) review processes are followed.
Stage 2: Build
In this stage, the source code is compiled and packaged into a runnable artifact.
- Action: The CI server runs build commands.
- Activities:
- Compile Code: For our Java project, this means running
./mvnw compile. - Run Unit Tests: Quick, isolated tests are run to verify individual pieces of code. This is often done with the same command, like
./mvnw test. - Package Application: The compiled code is packaged into an executable format. For us, this is the JAR file created by
./mvnw package. - Create Container Image: The
docker buildcommand is executed, using theDockerfileand the newly created JAR file to build a Docker image. This is exactly what you did manually in the last lesson.
- Compile Code: For our Java project, this means running
Stage 3: Test
Here, the packaged application undergoes more thorough testing to ensure quality and correctness.
- Action: The pipeline deploys the application to a temporary testing environment.
- Activities:
- Integration Tests: These tests verify that different parts of your application work together correctly (e.g., does the controller layer correctly call the service layer?).
- End-to-End (E2E) Tests: These simulate a full user workflow to test the application as a whole.
- Code Coverage Checks: Tools like JaCoCo and CodeCov can be used to measure what percentage of your code is covered by automated tests.
Stage 4: Deploy
Once the application has passed all tests, it is ready to be deployed.
- Action: The pipeline pushes the artifact to a registry and deploys it.
- Activities:
- Push to Registry: The validated Docker image is pushed to a container registry like Docker Hub or Amazon ECR.
- Deploy to Environment: The new image is pulled from the registry and deployed to a server. This could be a staging environment (a replica of production for final review) or, in the case of Continuous Deployment, directly to the production environment.
Test your understanding!
A developer pushes a change that breaks a unit test. In which stage of the CI/CD pipeline would this failure be caught, and what would happen next?
Show answer
The failure would be caught in the Build stage. During this stage, unit tests are typically executed (e.g., via mvn test). When the test fails, the pipeline will stop immediately and report the failure to the developer. The code will not proceed to the Test or Deploy stages, preventing the bug from reaching any environment.
Conclusion
You now have a conceptual map of the CI/CD pipeline, the automated assembly line for your software. You understand not just the stages but also the fundamental principles that make it so powerful.
Key Takeaways:
- CI/CD automates software delivery to increase speed, reduce errors, and lower stress.
- Continuous Integration (CI) is about frequently merging code and running automated builds and tests to catch issues early.
- Continuous Delivery automates the release process up to a manual production deployment, while Continuous Deployment automates the entire path to production.
- A typical pipeline consists of four main stages:
- Source: Triggered by a code commit.
- Build: Compiles code, runs unit tests, and creates a runnable artifact (like a Docker image).
- Test: Runs more extensive tests (integration, E2E) on the artifact.
- Deploy: Pushes the artifact to a registry and deploys it to one or more environments.
What's Next?
Understanding the theory is the first step. In the next lesson, Create a basic CI pipeline using GitHub Actions to build and test the application on code push, we will put this knowledge into practice. You will create your first CI pipeline for your Spring Boot project, configuring it to automatically run the Build stage every time you push code to GitHub. This will be your first major step in automating your development workflow.