Spring Boot CI/CD Pipeline with Jenkins

In modern software development, Continuous Integration and Continuous Deployment (CI/CD) is a must-have for delivering reliable features quickly. Jenkins, a powerful open-source automation tool, makes it easy to implement CI/CD for your Spring Boot microservices.

In this post, you’ll learn how to:

  • Set up a Jenkins pipeline for Spring Boot
  • Automate testing, Docker builds, and K8s deployments
  • Store build artifacts
  • Trigger builds on git commits or pull requests

We’ll use a sample app with base package:
com.kscodes.springboot.containers

Spring Boot CI/CD Pipeline with Jenkins

🧰 Prerequisites

Before you begin, make sure you have:

  • Docker installed on Jenkins host
  • Kubernetes cluster access (Minikube, GKE, etc.)
  • Jenkins with Docker, Git, and Kubernetes CLI tools installed
  • A Spring Boot project with a working Dockerfile
  • GitHub repository for code

🏗️ Step 1: Sample Spring Boot Project Structure

📜 Jenkinsfile (Declarative Pipeline)

Create a Jenkinsfile in your project root:

🐳 Step 2: Dockerfile

📄 Step 3: Kubernetes Deployment Template

Initially apply this once:

Later, Jenkins will just update the image version.

⚙️ Step 4: Jenkins Configuration

In Jenkins:

  • Create a new Pipeline project
  • Set GitHub repo URL
  • Ensure:
    • Jenkins has Docker access
    • Jenkins can run shell commands
    • kubectl and docker are in Jenkins PATH
  • Add Docker Hub credentials (if private) to Jenkins

🎯 Bonus: GitHub Webhooks

Automate builds on every push:

  • In GitHub → Settings → Webhooks
  • URL: http://<jenkins-url>/github-webhook/
  • Content type: application/json
  • Trigger: push events

Now Jenkins triggers CI/CD on every push or PR merge.

🛡️ Best Practices

PracticeWhy It Helps
Use semantic versioningMakes tracking and rollback easier
Use --record in kubectl set imageTracks changes in kubectl rollout
Separate test & deploy stagesPrevents broken code from going live
Monitor with Prometheus + GrafanaReal-time pipeline monitoring

📘 Summary

In this post, you built a Spring Boot Jenkins CI/CD pipeline to automate the entire software delivery process. From building and testing the app to Dockerizing it and deploying on Kubernetes — all without manual steps.

This setup enhances delivery speed, reduces risk, and ensures repeatable deployments across environments.

In the next post, we’ll explore how to deploy Spring Boot on AWS Elastic Beanstalk as an alternative cloud deployment strategy.