This is a complete Jenkins CI/CD pipeline that increments the application version, builds the Maven JAR and Docker image, pushes the image to Docker Hub, deploys the application to EC2 with Docker Compose, and commits the version update back to the repository.
deploy-to-k8s- deploys an NGINX workload from Jenkins to AWS EKS usingkubectland AWS IAM authentication.jenkins-lke- deploys an NGINX workload from Jenkins to Linode Kubernetes Engine (LKE) using a Jenkins-managed kubeconfig.ci-cd-eks- Complete CI/CD pipeline that increments the Maven version, builds the JAR and Docker image, pushes the image to Docker Hub, applies the Kubernetes Deployment and Service to AWS EKS, then commits the version update.ci-ecr-eks- Complete CI/CD pipeline that increments the Maven version, builds the JAR and Docker image, pushes the image to Amazon ECR, applies the Kubernetes Deployment and Service to AWS EKS, then commits the version update.
- AWS, Jenkins, Docker, Linux, Git, Java, Maven, Docker Hub
This project implements a complete CI/CD flow for the Java Maven application. It covers dynamic versioning, artifact creation, Docker image publishing, and deployment through Docker Compose on EC2.
- Loads local Groovy helpers from
script.groovy. - Increments the Maven version before the build.
- Builds the application with Maven.
- Builds and pushes the Docker image to Docker Hub.
- Deploys the new application version on EC2 using Docker Compose and
server-cmds.sh. - Commits the version update back to
master.
init- Loads
script.groovy. - Prints the startup messages.
- Loads
increment version- Runs the Maven version bump using
build-helper:parse-versionandversions:set. - Reads the updated version from
pom.xml. - Sets
IMAGE_NAMEto<version>-<build number>.
- Runs the Maven version bump using
build jar- Runs
gv.buildJar(). - Executes
mvn clean package.
- Runs
build image- Runs
gv.buildImage(). - Builds the Docker image as
anantluthra/simple-java-app:${IMAGE_NAME}. - Logs in to Docker Hub with Jenkins credentials.
- Pushes the image to Docker Hub.
- Runs
deploy- Copies
docker-compose.yamlandserver-cmds.shto the EC2 host. - Uses
server-cmds.shto export the target image and start the stack. - Starts the updated application container with Docker Compose.
- Uses Docker Compose to manage the application container and the Postgres service.
- Copies
commit version update- Configures the Git user in the Jenkins agent.
- Commits the version bump.
- Pushes the change back to
master.
Jenkinsfile- declarative Jenkins pipeline.script.groovy- local pipeline helper functions.server-cmds.sh- remote deployment helper script.docker-compose.yaml- Docker Compose definition for the app and Postgres.src/main- Spring Boot application source.src/test- application tests.Dockerfile- container build definition.
- Jenkins with the Maven tool configured as
maven-3.9. - Docker access on the Jenkins agent.
- Jenkins credentials with id
docker-hub-repo. - Jenkins credentials with id
git-credentials.
Dockerfileusesamazoncorretto:17-alpine-jdk, exposes port8080, and runs the packaged jar from/usr/app.- The image tag is based on the application version plus the Jenkins build number.
- The pipeline keeps the build, image, deploy, and version update logic in one place without using a shared library.
- The deploy step uses a shell script plus Docker Compose instead of a manual container run command.
- Other related branches in this repo are
jenkins-jobfor the exploratory Jenkins job flow,jen-shared-libfor the shared-library based pipeline, andcd-pipefor the complete CI/CD flow with a project-specific shared library.