Automate Spring Boot Deployment with Jenkins: A Step‑by‑Step Guide
This article walks you through setting up Jenkins to clone a Spring Boot project from Gitee, configure JDK, Git, and Maven tools, create a freestyle job with parameterized builds, write shell scripts for stopping and starting the application, and troubleshoot common issues for a fully automated CI/CD pipeline.
1. Jenkins Overview
Jenkins is an open‑source Java‑based continuous integration tool that automates repetitive tasks, making build and deployment processes easier for testing and operations.
2. Environment Preparation
The following tools are required:
JDK
Git
Maven
Images of the installed tools are shown below.
3. Jenkins Tool Plugin Configuration
3.1 Plugin Installation
It is recommended to install the default suggested plugins, which include Maven and Git plugins.
3.2 Tool Configuration
JDK
Git
Maven
4. Project Configuration
4.1 Create a Freestyle Project
Create a new freestyle project, give it a name, and click OK.
4.2 Parameterized Build
Define parameters such as jar_path, spring_profile, jar_name, and project_name to customize the build.
4.3 Git Configuration
Configure the repository URL and credentials to clone the project.
4.4 Build Step
Use an Execute Shell step with the following commands:
mvn clean install -Dmaven.test.skip=true echo $spring_profile $jar_path $jar_name cd /usr/local/shell/ ./stop.sh $jar_name echo "Execute shell Finish" ./startup.sh $spring_profile $jar_path $jar_name $project_name4.5 stop.sh Script
jar_name=${1}
echo "Stopping" ${jar_name}
pid=`ps -ef | grep ${jar_name} | grep -v grep | awk '{print $2}'`
if [ -n "$pid" ]
then
echo "kill -9 的pid:" $pid
kill -9 $pid
fi4.6 startup.sh Script
spring_profile=${1}
jar_path=${2}
jar_name=${3}
project_name=${4}
cd ${jar_path}/${project_name}/target/
echo ${jar_path}/${project_name}/target/
echo nohup java -jar ${jar_name} &
BUILD_ID=dontKillMe nohup java -jar ${jar_name} --spring.profiles.active=${spring_profile} &5. Test Run
Run the job; if Maven is not found, create a symbolic link to the Maven binary:
ln -s /usr/local/apache-maven-3.5.4/bin/mvn /usr/bin/mvnAfter successful execution, the Spring Boot application is accessible.
6. Conclusion
The process involves many steps and occasional issues, but with careful configuration the Jenkins pipeline can fully automate building and deploying a Spring Boot application.
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.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
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.
