Operations 7 min read

One-Click Automated Deployment of Spring Boot with Jenkins and Docker

This tutorial provides a complete, step‑by‑step guide to set up a one‑click automated deployment pipeline for a Spring Boot application using Docker, Jenkins, Maven, and shell scripts on a CentOS 7 host, covering installation, configuration, job creation, testing, and execution.

Architecture Digest
Architecture Digest
Architecture Digest
One-Click Automated Deployment of Spring Boot with Jenkins and Docker

This article demonstrates how to achieve a simple yet comprehensive one‑click automated deployment of a Spring Boot project using Jenkins, Docker, and shell scripts on a CentOS 7 environment.

Environment : CentOS 7 with Git (Gitee).

Install Docker

Update yum packages yum update<br/> Remove old Docker versions if present

yum remove docker docker-common docker-selinux docker-engine<br/>

Install required utilities

yum install -y yum-utils device-mapper-persistent-data lvm2<br/>

Add Docker CE repository

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo<br/>

Install Docker CE (stable version)

yum install docker-ce  # installs the latest stable version (e.g., 17.12.0)
# or specify a version, e.g., yum install docker-ce-17.12.0.ce<br/>

Start Docker and enable on boot

systemctl start docker
systemctl enable docker<br/>

Verify installation

docker version<br/>

Install Jenkins

Run Jenkins in a Docker container:

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/blueocean<br/>

Access Jenkins at http://{JENKINS_HOST_IP}:8080 and complete the initial setup by retrieving the admin password:

docker exec -it jenkins bash
cat /var/lib/jenkins/secrets/initialAdminPassword<br/>

Install recommended plugins, create an admin user, and unlock Jenkins.

System Configuration

Navigate to Home → Manage Jenkins → Manage Plugins → Available and install the following plugins:

Maven Integration

Publish Over SSH (optional)

Gitee (if using Gitee, Git is built‑in)

Configure Maven under

Global Tool Configuration

Create a Jenkins Job

Click New Item, enter a job name, and select “Freestyle project”.

Configure source code management: Git → Repository URL, Credentials Set build triggers as needed, then add a build step “Invoke top‑level Maven targets” with goals: clean install -Dmaven.test.skip=true<br/> Save the job.

Test the Build

Click “Build Now”, then view the console output to ensure the JAR is produced. If dependencies fail on the first run, rebuild.

Check the workspace location:

cd /var/jenkins_home/workspace
ll<br/>

Run the Project

Create a Dockerfile 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 ["Bash","-DBash.security.egd=file:/dev/./urandom","-jar","/app.jar","--spring.profiles.active=prd"]<br/>

Update the Jenkins job to build the Docker image and run the container:

# In a shell build step
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:latest<br/>

Note: the || true ensures the pipeline continues even if a command fails.

After saving, trigger a build, then verify the container is running:

docker ps
docker logs zx-order<br/>

Finally, open a browser to the application URL to confirm successful deployment.

END

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ci/cdautomationDevOpsSpring BootJenkins
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.