One-Click Automated Deployment of Spring Boot Projects Using Jenkins, Docker, and Maven
This tutorial provides a step‑by‑step guide to set up a complete Jenkins‑Docker‑Spring Boot pipeline on CentOS 7, covering Docker installation, Jenkins deployment, required plugins, Maven configuration, job creation, testing, and running the packaged application with Docker.
This article demonstrates a comprehensive, one‑click solution for automatically deploying Spring Boot projects using Jenkins, Docker, and Maven on a CentOS 7 environment with Git (Gitee) as the source repository.
Environment : CentOS 7, Git (Gitee).
Step 1 – Install Docker
Update yum, remove old Docker versions, install required utilities, add the Docker yum repository, and install Docker CE. Then start Docker, enable it on boot, and verify the installation:
yum update yum remove docker docker-common docker-selinux docker-engine yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum install docker-ce systemctl start docker systemctl enable docker docker versionStep 2 – Install Jenkins
Run Jenkins in a Docker container, ensuring port 8080 is free:
docker run --name jenkins -u root --rm -d -p 8080:8080 -p 50000:50000 -v /var/jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueoceanAccess Jenkins at http://{JENKINS_HOST_IP}:8080 and follow the initial setup instructions on the official Jenkins site.
Unlock Jenkins by retrieving the admin password from the container:
# Enter the Jenkins container
docker exec -it {JENKINS_CONTAINER_NAME} bash
# View the initial admin password
cat /var/lib/jenkins/secrets/initialAdminPasswordInstall the recommended plugins, then create an administrator account.
Step 3 – System Configuration
Install additional plugins needed for Maven builds and Gitee integration:
Maven Integration
Publish Over SSH (optional)
Gitee (if using Gitee as the Git host)
Configure Maven under Manage Jenkins → Global Tool Configuration by adding a Maven installation.
Step 4 – Create a Jenkins Job
Create a new Freestyle project, set the Git repository URL and credentials, and add a build step that runs the Maven command: clean install -Dmaven.test.skip=true Save the job configuration.
Step 5 – Test the Build
Trigger a build, monitor the console output, and verify that a JAR file is produced. If the first build fails to download dependencies, re‑run the build.
Check the workspace directory to confirm the presence of the built artifacts: cd /var/jenkins_home/workspace Step 6 – Run the Project
Because Jenkins and the application run on the same host, use a shell script to build a Docker image from a Dockerfile and run the container.
Dockerfile example (place it in the Spring Boot project root):
FROM jdk:8
VOLUME /tmp
ADD target/zx-order-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8888
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar","--spring.profiles.active=prd"]In the Jenkins job, add a build step that executes the following commands to build and run the Docker image:
cd /var/jenkins_home/workspace/zx-order-api
docker stop zx-order || true
docker rm zx-order || true
docker rmi zx-order || true
docker build -t zx-order .
docker run -d -p 8888:8888 --name zx-order zx-order:latestNote: Using docker logs -f is convenient for debugging but should be avoided in production pipelines because it blocks the build.
After the build completes, verify the container is running and view its logs:
docker ps
docker logs zx-orderFinally, access the application at http://{HOST_IP}:8888.
Conclusion
The guide walks through installing Docker and Jenkins, configuring Maven, creating a Jenkins job, testing the build, and deploying a Spring Boot application via Docker, providing a reproducible CI/CD pipeline for Java backend services.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Code Ape Tech Column
Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
