Operations 22 min read

Master Jenkins Automated Deployment: From Code Commit to Live Release

This article provides a step‑by‑step guide to setting up Jenkins for automated CI/CD, covering pipeline workflow, installation, required plugins, global tool configuration, Gitee and SSH integration, Maven project setup, post‑build deployment scripts, and how to run and verify builds.

Raymond Ops
Raymond Ops
Raymond Ops
Master Jenkins Automated Deployment: From Code Commit to Live Release

Master Jenkins Automated Deployment: From Code Commit to Live Release

Jenkins automation deployment is essential in modern software development, simplifying code release, improving team efficiency, and enabling continuous integration and delivery (CI/CD). It allows developers to focus on code while Jenkins handles building, testing, and deploying automatically.

1. Jenkins Workflow

When code is submitted, Jenkins triggers a pipeline that monitors repository changes, starts builds, runs tests, packages artifacts, and deploys to servers.

1. Source Code Management (SCM) polling or Webhooks

SCM polling : Jenkins periodically checks the repository for changes and triggers a build when a new commit is detected.

Webhooks : The repository sends an HTTP request to Jenkins immediately after a commit, enabling near‑real‑time builds.

2. Trigger Build Task

Jenkins uses a Pipeline defined in a Jenkinsfile (Groovy script) to orchestrate the whole process.

3. Pipeline Stages

Checkout code : Pull the latest source from the SCM.

Build : Compile and package the code with Maven, Gradle, or other tools.

Test : Execute unit, integration, and functional tests.

Code quality analysis (optional) : Run SonarQube or similar tools.

Deploy : Transfer the built artifact to development, testing, or production environments via SSH, Docker, Kubernetes, or cloud APIs.

4. Master‑Agent Collaboration

The Jenkins master schedules jobs and manages agents that execute the actual build steps.

5. Jenkinsfile (Pipeline Script)

The Jenkinsfile stores the pipeline definition in the source repository, allowing version‑controlled, reproducible builds.

2. Install Jenkins

1. Create data directory

# Create jenkins directory
mkdir /data/jenkins_home/
# Change ownership so the container can access it
chown -R 1000:1000 /data/jenkins_home/

2. Pull Jenkins image

docker pull jenkins/jenkins:lts

3. Start Jenkins container

Run Jenkins on port 8088 to avoid conflict with Spring Boot's default 8080.

docker run -d --name jenkins -p 8088:8080 -p 50000:50000 -v /data/jenkins_home:/var/jenkins_home jenkins/jenkins:lts

4. Access Jenkins

Open http://<em>your‑server‑ip</em>:8088 and enter the initial admin password located at /data/jenkins_home/secrets/initialAdminPassword.

3. Install Maven

Maven is required for building Java projects, handling compilation, dependency management, testing, and packaging.

Download Maven Use wget to fetch the binary archive.

wget https://dlcdn.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz

Extract archive Extract to /opt.

sudo tar -zxvf apache-maven-3.8.8-bin.tar.gz -C /opt

Configure environment variables

export M2_HOME=/opt/apache-maven-3.8.8
export PATH=$M2_HOME/bin:$PATH

Apply changes source /etc/profile Verify installation

mvn -version

4. Install Plugins

After Jenkins starts, install the following plugins to support Gitee integration, Maven builds, and SSH deployment.

1. Gitee

Function : Integrates Jenkins with Gitee repositories.

Installation : Search “Gitee” in Plugin Manager and install.

2. Maven Integration

Function : Allows Jenkins to invoke Maven directly.

Installation : Search “Maven Integration” and install.

3. Publish Over SSH

Function : Transfers build artifacts to remote servers via SSH.

Installation : Search “Publish Over SSH” and install.

5. Global Tool Configuration

Configure JDK, Maven, and Git in “Manage Jenkins → Global Tool Configuration” so that pipelines can locate these tools.

6. System Configuration

Configure Publish Over SSH and Gitee in “Manage Jenkins → Configure System”. Provide SSH server details, authentication method, and Gitee API token.

7. Build Project

Create a new Maven project, set SCM to your Gitee repository, configure build triggers (polling or webhook), specify pom.xml and Maven goals (e.g., clean install), and add post‑build actions such as Deploy via SSH.

8. Post‑Build Deploy Script

# Set JDK path
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk
export PATH=$JAVA_HOME/bin:$PATH

# Define JAR location
JAR_PATH=/root/deploy_data
JARFILE=webserver-1.0.0-SNAPSHOT.jar

# Kill existing process
ps -ef | grep $JARFILE | grep -v grep | awk '{print $2}' | xargs kill -9

# Start new process
nohup java -jar -Xms512m -Xmx1024m $JAR_PATH/$JARFILE > out.log 2>&1 &

if [ $? -eq 0 ]; then
  sleep 30
  tail -n 50 out.log
fi

9. Run and Verify Build

Save the configuration, click “Build Now”, and monitor the console output. A green “Success” indicates a successful pipeline; a red “Failure” signals issues that need fixing.

Maven version output
Maven version output
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/cdmavenJenkinsSSH
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

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.