Spring Boot CI/CD with GitHub Actions

In today’s fast-paced development cycle, Continuous Integration (CI) and Continuous Deployment (CD) are essential for building reliable, testable, and deployable applications.

In this post, we’ll walk you through integrating Spring Boot CI/CD with GitHub Actions. You’ll learn how to:

  • Set up automated tests and builds
  • Generate test reports
  • Run integration and unit tests
  • Use best practices for GitHub workflow design

We’ll use a sample project in the package com.kscodes.springboot.

Spring Boot CI/CD with GitHub Actions

🧾 Project Structure

πŸ“˜ HelloController.java

πŸ“˜ GreetingService.java

βœ… Test File Example

πŸ“— GreetingServiceTest.java

πŸ§ͺ Step 1: Add GitHub Actions Workflow

Create a workflow file at:

πŸ› οΈ springboot-ci.yml

πŸ“Š Output from Workflow

  • βœ… Runs mvn clean verify
  • βœ… Executes unit tests and integration tests
  • βœ… Uploads surefire-reports with test results
  • βœ… Fails PRs on test failures

🧠 Optional: Add Code Coverage with JaCoCo

Add to pom.xml:

This will produce target/site/jacoco/index.html after test runs. You can optionally upload it to GitHub Artifacts:

🧠 Best Practices for Spring Boot CI/CD with GitHub Actions

PracticeBenefit
βœ… Use verify not just testIncludes linting, integration checks
βœ… Separate jobs for test/build/deployBetter control and caching
βœ… Use conditional upload of artifactsOnly when needed (if: always())
βœ… Add coverage badges in READMETransparency on code quality
βœ… Fail fast on test failuresPrevent bad code from merging

πŸ” Deployment (Optional CI/CD)

If you want to auto-deploy on a successful build:

Or use GitHub Actions integrations with:

  • DockerHub (docker/build-push-action)
  • AWS Elastic Beanstalk / ECS
  • Azure App Service
  • Kubernetes via kubectl

πŸ“š Summary

You now have a complete working pipeline for Spring Boot CI/CD with GitHub Actions! In this post, you:

  • Created a working Spring Boot project with tests
  • Set up GitHub Actions to automate builds and test reports
  • Learned best practices for reliable and maintainable CI/CD pipelines