Operations 7 min read

Automate Gitee Project Builds with Jenkins, Maven, and Shell Scripts

This guide walks through setting up Jenkins to clone a Gitee repository, configure Maven and Git plugins, define a parameterized freestyle job, and use shell scripts to build and launch a Spring Boot application, including troubleshooting steps for Maven path issues.

Programmer DD
Programmer DD
Programmer DD
Automate Gitee Project Builds with Jenkins, Maven, and Shell Scripts

1. Jenkins Overview

Jenkins is an open‑source Java‑based continuous‑integration server that automates repetitive development tasks.

2. Environment Preparation

Required tools: JDK, Git, Maven, and Jenkins.

JDK

Git

Maven

Jenkins (installed with the following commands)

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 start
vi /var/lib/jenkins/secrets/initialAdminPassword

3. Jenkins Plugin Configuration

Install the recommended plugins on first start, and additionally add Maven and Git plugins if needed.

4. Project Configuration

4.1 Create a Freestyle Project

Create a new freestyle job, give it a name, and save.

4.2 Parameterized Build

jar_path – workspace path for the built JAR

spring_profile – profile name (dev, test, prod)

jar_name – name of the JAR file

project_name – name of the project

4.3 Git Settings

Configure the repository URL and credentials to clone the project from Gitee.

4.4 Build Step (Shell)

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_name

stop.sh (stops the running JAR) and startup.sh (starts the JAR with the selected profile) are used:

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}
fi
spring_profile=${1}
jar_path=${2}
jar_name=${3}
project_name=${4}
cd ${jar_path}/${project_name}/target/
nohup java -jar ${jar_name} --spring.profiles.active=${spring_profile} &

5. Test Run

Run the job, adjust parameters if needed, and ensure Maven is reachable by linking it to /usr/bin:

ln -s /usr/local/apache-maven-3.5.4/bin/mvn /usr/bin/mvn

6. Summary

The process involves several pitfalls, but following the steps above allows Jenkins to clone, build, and launch a Spring Boot application automatically.

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/cdmavenGiteeJenkins
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

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.