Using Jenkins to Clone a Gitee Project, Build with Maven, and Deploy via Shell Scripts
This article walks through installing Jenkins, preparing the environment with JDK, Git, and Maven, configuring Jenkins plugins and a freestyle job, defining build parameters and shell scripts to clone a Gitee repository, build a Spring Boot jar with Maven, stop any running instance, and start the new application, followed by troubleshooting tips and a final summary.
Jenkins is introduced as an open‑source continuous‑integration tool built on Java that automates repetitive deployment tasks.
Environment preparation : The tutorial lists the required tools—JDK, Git, and Maven—and shows how to install Jenkins on a Red Hat‑based system:
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key sudo yum install jenkins service jenkins startAfter starting Jenkins, the user accesses http://${ip}:8080 to complete the initial setup and retrieve the admin password.
Jenkins plugin configuration : It is recommended to accept the default plugin set and additionally install the Maven and Git plugins.
Project configuration : A freestyle job is created with four parameters— jar_path , spring_profile , jar_name , and project_name . The Git repository URL (hosted on Gitee) is configured, and a Shell build step is defined:
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_nameThe stop.sh script locates the running jar process and kills it if found:
pid=`ps -ef | grep ${jar_name} | grep -v grep | awk '{print $2}'`
if [ -n "$pid" ]; then
echo "kill -9 的pid:" $pid
kill -9 $pid
fiThe startup.sh script changes to the jar directory and launches the application with the selected Spring profile:
cd $jar_path/$project_name/target/
nohup java -jar $jar_name &
BUILD_ID=dontKillMe nohup java -jar $jar_name --spring.profiles.active=$spring_profile &Test run : After triggering the job, the parameters can be reviewed and modified. An issue where Jenkins could not find the mvn command is resolved by linking the Maven binary to /usr/bin/mvn :
ln -s /usr/local/apache-maven-3.5.4/bin/mvn /usr/bin/mvnThe job runs successfully and the deployed Spring Boot application is accessible via the blog URL.
Conclusion : Although the setup involves many small pitfalls, the overall process of using Jenkins to clone a Gitee project, build it with Maven, and manage deployment through shell scripts is achievable and can be refined through further experimentation.
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.
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.