Operations 21 min read

Master Jenkins Automation: From Code Commit to Seamless Deployment

This guide walks you through the complete Jenkins CI/CD workflow—from source‑code changes triggering automated builds, tests, and packaging to secure deployment—showing how to set up Jenkins, configure pipelines, install essential plugins, and manage global tools for reliable, hands‑free releases.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Jenkins Automation: From Code Commit to Seamless Deployment

Master Jenkins Automation: From Code Commit to Automatic Deployment

Jenkins automation deployment is essential in modern software development, simplifying release processes and improving team efficiency. Developers can focus on writing high‑quality code while Jenkins handles building, testing, and deploying automatically.

Jenkins Workflow

When code is submitted, Jenkins triggers a pipeline that monitors SCM changes, builds, tests, packages, and deploys the application.

1. Source Code Management (SCM) Polling or Webhooks

SCM Polling : Jenkins periodically checks the repository for new commits.

Webhooks : The SCM sends an HTTP request to Jenkins immediately after a commit.

2. Trigger Build

Jenkins uses a Pipeline defined in a Groovy script to process the build.

3. Pipeline Stages

Checkout : Pull the latest code from the repository.

Build : Compile and package with Maven, Gradle, or create Docker images.

Test : Run unit, integration, and functional tests.

Code Quality (Optional) : Analyze with SonarQube.

Deploy : Transfer artifacts to target environments via SSH, Docker, or cloud APIs.

4. Master‑Agent Architecture

The Jenkins master schedules jobs and monitors agents, while agents execute the actual build steps.

5. Jenkinsfile

The pipeline is defined in a Jenkinsfile stored in the source repository, enabling version‑controlled CI/CD.

6. Notifications

Jenkins provides real‑time logs and can send email or Slack notifications on success or failure.

Setting Up Jenkins

1. Create Data Directory

# Create jenkins directory
mkdir /data/jenkins_home/
chown -R 1000:1000 /data/jenkins_home/

2. Pull Jenkins Image

docker pull jenkins/jenkins:lts

3. Run Jenkins Container

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

Access Jenkins at http://<host>:8088 and retrieve the initial admin password from /data/jenkins_home/secrets/initialAdminPassword.

Jenkins login screen
Jenkins login screen

4. Install Maven

Maven is used to compile Java projects, manage dependencies, run tests, and package artifacts.

Download Maven:

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

Extract:

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

Verify installation:

mvn -version

5. Install Plugins

Install the following plugins via “Manage Plugins” to integrate with Gitee, Maven, and SSH deployment:

Gitee : Enables Jenkins to pull code from Gitee repositories and trigger builds.

Maven Integration : Allows Jenkins to invoke Maven directly for builds.

Publish Over SSH : Transfers build artifacts to remote servers securely.

Jenkins plugin management
Jenkins plugin management

6. Global Tool Configuration

Configure the following tools under “Global Tool Configuration”:

JDK : Required for Jenkins itself and for Java builds.

Maven : Used for building Java projects.

Git : Source‑code management.

Gradle (optional) : For projects that use Gradle.

7. Create Maven Project

In Jenkins, create a new Maven project, set the SCM repository URL, choose build triggers (polling or webhook), and specify the root pom.xml and Maven goals such as clean install or package.

8. Post‑Build Actions

Add steps like “Publish Over SSH” to deploy the generated JAR/WAR to a remote server.

9. Deploy Script Example

# Set JDK path
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.23.0.9-2.el7_9.x86_64
export PATH=$JAVA_HOME/bin:$PATH

# Set JAR path and name
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

Adjust the script according to the server’s JDK location and JAR name.

After saving the configuration, click “Build Now” to start the first build and monitor the console output for success or failure.

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.

Dockerci/cdDevOpsmavenPipelineJenkins
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.