Operations 13 min read

Master Jenkins: Step-by-Step Guide to Automated CI/CD Deployment on Linux

This comprehensive tutorial explains what Jenkins is, why CI/CD matters, and provides step‑by‑step instructions for installing JDK and Jenkins on Linux, configuring Git and Maven integration, setting up credentials and password‑less SSH, and creating deployment scripts to automate Java application builds and releases.

Open Source Linux
Open Source Linux
Open Source Linux
Master Jenkins: Step-by-Step Guide to Automated CI/CD Deployment on Linux

Jenkins Tutorial (Automated Deployment)

1. What is Jenkins?

Jenkins is an open‑source continuous integration (CI) tool written in Java, providing a user‑friendly interface for automated building, testing and deployment. It can run in servlet containers such as Tomcat or as a standalone application and is typically used together with SCM and build tools.

2. What is CI/CD?

CI/CD automates code testing, packaging and release, allowing developers to focus on coding while the tool handles repetitive tasks, improving efficiency and reducing errors.

3. Installing Jenkins

(1) Prepare environment – install JDK

Download a JDK tarball, extract it, configure environment variables in /etc/profile, source the file and verify with javac.

# vim /etc/profile
export JAVA_HOME=/usr/wubin/jdk11
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
source /etc/profile
javac

Successful output confirms JDK installation.

(2) Install Jenkins

Download the latest jenkins.war and start it with nohup on ports 8777/8778.

wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war
nohup java -jar /usr/wubin/jenkins.war --httpPort=8777 --httpsPort=8778 > /usr/wubin/jenkins.log 2>&1 &

Check the log with tail to obtain the initial admin password, then open http://<your‑ip>:8777 in a browser and install the recommended plugins.

(3) Configure JDK path in Jenkins

Navigate to “Manage Jenkins → Global Tool Configuration → JDK” and add the JDK installation.

(4) Reset forgotten Jenkins password

Follow the on‑screen instructions to reset the admin password.

4. Integrate Git

Install Git on the Jenkins host ( yum install git -y) and add the Git plugin in Jenkins. Create a repository on Gitee (or GitHub) and configure credentials so Jenkins can pull the code.

5. Configure Credentials

Install the “Credentials Binding” plugin, then add database, Gitee or Docker passwords under “Manage Jenkins → Configure System → Security → Manage Credentials”.

6. Maven Integration

Download and extract Maven, set MAVEN_HOME and update PATH in /etc/profile, then source the file and verify with mvn -version. In Jenkins, install the Maven plugin, create a local repository directory, and configure settings.xml to use the Alibaba Cloud mirror.

# cd /usr/wubin/
# wget https://mirrors.aliyun.com/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
# tar -zxvf apache-maven-3.6.3-bin.tar.gz
export MAVEN_HOME=/usr/wubin/apache-maven-3.6.3
export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
source /etc/profile
mvn -version

7. Configure SSH password‑less login

Generate an RSA key pair on the Jenkins server, copy the public key to the target application server’s ~/.ssh/authorized_keys, and ensure .ssh permissions are 700 and authorized_keys is 600. Test the connection with ssh root@<target‑ip>.

# ssh-keygen -t rsa   # press Enter three times
# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
# chmod 700 ~/.ssh
# chmod 600 ~/.ssh/authorized_keys
# scp -p ~/.ssh/id_rsa.pub [email protected]:/root/.ssh/authorized_keys
# ssh [email protected]

8. Write Jenkins deployment script

#!/bin/bash
DIR="/data/app"
projectName="my-boot"
server_ips=("192.168.223.139")
for server_ip in "${server_ips[@]}"; do
  ssh -Tq -o StrictHostKeyChecking=no root@${server_ip} <<EOF
mkdir -p $DIR/backup/${projectName}
mkdir -p $DIR/${projectName}
if [ -f "$DIR/${projectName}/${projectName}.jar" ]; then
  mv $DIR/${projectName}/${projectName}.jar $DIR/backup/${projectName}/${projectName}-$(date "+%Y%m%d_%H%M%S").jar
fi
EOF
  scp -q -o StrictHostKeyChecking=no ${WORKSPACE}/target/*.jar root@${server_ip}:/tmp/${projectName}.jar
  ssh -q -o StrictHostKeyChecking=no root@${server_ip} <<EOF
mv /tmp/${projectName}.jar $DIR/${projectName}/${projectName}.jar
EOF
done
echo "success"

9. Write application start/stop scripts

Start script ( start.sh) launches the jar with nohup java -jar and checks the log for “Started”.

#!/bin/bash
APP_ID=my-boot
APP_DIR="/data/app"
nohup java -jar ${APP_DIR}/${APP_ID}/${APP_ID}.jar > release_out.log &
# check log for "Started"
if grep -q "Started" release_out.log; then
  echo "Application started ok"
else
  echo "Application started error"
fi

Stop script ( stop.sh) kills the process by name.

#!/bin/bash
APP_ID=my-boot
ps aux | grep ${APP_ID} | grep -v grep | awk '{print "kill -9 "$2}' | sh

10. Open firewall port and test service

Allow port 9010 on the application server and access the service at http://192.168.223.129:9010.

# firewall-cmd --zone=public --add-port=9010/tcp --permanent
# firewall-cmd --reload
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/cdGitJenkinsSSH
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

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.