Jenkins Spring Boot CI/CD Pipeline: 5 Easy Steps to Master Automation

Automating software deployments with Jenkins (CI/CD) is essential in modern tech. As a DevOps Engineer, my job is to ensure code moves from a laptop to a live server automatically and without errors.

We built an automated pipeline for the Spring Petclinic app. You will learn how to connect:

  • Jenkins for automation
  • Maven for building
  • Docker for containerization
  • Kubernetes for deployment

Prerequisites

  1. Before starting, ensure you have the following tools configured:
  2. GitHub Account: To host the springboot-docker-kubernetes-cicd repository.
  3. Jenkins Server: With Git, Docker, and Kubernetes CLI plugins installed.
  4. Docker Hub Account: To store your container images.
  5. Kubernetes Cluster: (Minikube, K3s, or a cloud provider like AWS EKS).
  6. Build Tools: Java and Maven installed on your Jenkins agent.

ALSO READ:

Click here to go to the GitHub repos link

The CI/CD Process Overview

The pipeline follows a logical, five-stage process:

  1. Fetch: Pull the latest code from GitHub.
  2. Build: Use Maven to compile and package the Spring Boot .jar file.
  3. Containerize: Build a Docker image containing the application.
  4. Push: Upload the image to Docker Hub for centralized access.
  5. Deploy: Update the Kubernetes cluster with the new image.

Step-by-Step Implementation Guide

Step 1: Source Code Management (GitHub)

The project starts with a push to GitHub. My repository includes the Spring Boot source code, a Dockerfile for containerization, and a deploymentservice.yaml file for Kubernetes orchestration.

Step 2: Automated Build with Maven

Once triggered, Jenkins runs mvn clean install`. This step is crucial as it runs unit tests and compiles the code. If a single test fails, the pipeline stops, ensuring that “broken” code never reaches your users.

Step 3: Creating the Docker Image

After a successful build, Jenkins uses the Dockerfile to create a lightweight container image. I use an optimized OpenJDK base image to ensure the container is fast and secure.

Step 4: Secure Image Registry (Docker Hub)

The pipeline logs into Docker Hub using encrypted Jenkins credentials. The image is tagged (e.g., tummetikrishna/spring-petclinic:latest) and pushed to the registry, making it accessible to the Kubernetes cluster.

Step 5: Kubernetes Deployment & Verification

Finally, the pipeline connects to the Kubernetes cluster. It executes kubectl apply -f deploymentservice.yaml, which triggers a rolling update. Kubernetes replaces the old pods with new ones, ensuring the application remains online during the update.

Leave a Comment