Jenkins自动化构建+gitlab+项目
Jenkins+gitlab+项目部署(若依项目)
环境准备#
主机名称 | IP地址 | 运行服务 | 配置 |
---|---|---|---|
gitlab | 192.168.13.121 | gitlab | 2cpu 4G |
jenkins | 192.168.13.123 | Jenkins nodeJS(打包前端代码) Maven(打包后端代码)Tomcat运行Jenkins服务 | 2cpu 4G |
Nginx | 192.168.13.113 | Nginx、MySQL | 1cpu 1G |
java | 192.168.13.122 | 后端服务、JDK1.8(运行后端代码)、Redis | 1cpu 1G |
有条件的可以将MySQL和 Redis 单独创建一个机器
静态web服务器准备#
Nginx安装
[root@nginx ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[root@nginx ~]# yum -y install nginx
[root@nginx ~]# nginx -v
nginx version: nginx/1.26.1
MySQL5.7安装与配置
- 安装MySQL5.7
#>>> 卸载旧依赖
[root@nginx ~]# yum -y erase `rpm -qa | grep mariadb`
[root@nginx ~]# rm -rf `find / -name mysql`
#>>> 安装wget
[root@nginx ~]# yum install -y wget yum-utils
#>>> 安装MySQL 安装源
[root@nginx ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
[root@nginx ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
#>>> 启动MySQL5.7安装源
[root@nginx ~]# vim /etc/yum.repos.d/mysql-community.repo
[root@nginx ~]# vim /etc/yum.repos.d/mysql-community-source.repo
#>>> 安装MySQL5.7
[root@nginx ~]# yum -y install mysql-server
#>>> 启动MySQL
[root@nginx ~]# systemctl enable --now mysqld
#>>> 查看密码
[root@nginx ~]# grep "password" /var/log/mysqld.log
2024-09-17T06:53:45.984526Z 1 [Note] A temporary password is generated for root@localhost: *=s0J&w%B<r5
- 修改root密码
#>>> 登录MySQL
[root@nginx ~]# mysql -uroot -p'*=s0J&w%B<r5'
#>>> 修改root密码
mysql> set password=password('12QW!@qw');
mysql> flush privileges;
- 修改配置文件
[root@nginx ~]# vim /etc/my.cnf #添加以下信息 注意不要重复
[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8
default-time_zone = '+8:00'
# 新建数据库添加的配置信息
lower_case_table_names=1
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci
max_connections=10000
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
#>>> 重启MySQL
[root@nginx ~]# systemctl restart mysqld
- 拉取源码
[root@nginx ~]# yum -y install git #git用于拉取项目的源码并将其推送到gitlab仓库
[root@nginx ~]# git clone https://gitee.com/y_project/RuoYi-Vue.git
正克隆到 'RuoYi-Vue'...
remote: Enumerating objects: 16754, done.
remote: Counting objects: 100% (261/261), done.
remote: Compressing objects: 100% (166/166), done.
remote: Total 16754 (delta 64), reused 145 (delta 34), pack-reused 16493
接收对象中: 100% (16754/16754), 4.02 MiB | 2.92 MiB/s, done.
处理 delta 中: 100% (8472/8472), done.
- 导入数据表
#>>> 创建数据库 并创建一个项目用户
[root@nginx ~]# mysql -uroot -p'12QW!@qw'
mysql> create database ruoyi character set utf8mb4;
mysql> grant all on ruoyi.* to ruoyi@'%' identified by '12QW!@qw';
mysql> flush privileges;
#>>> 切换目录
[root@nginx ~]# cd RuoYi-Vue/sql/
#>>> 导入数据
[root@nginx sql]# mysql -uroot -p ruoyi < ry_20240629.sql #输入密码
Enter password:
[root@nginx sql]# mysql -uroot -p ruoyi < quartz.sql
Enter password:
#>>> 查看数据是否导入
mysql> use ruoyi
mysql> show tables;
后端应用服务器准备#
安装JDK1.8
# 准备一个jdk1.8的版本
[root@java ~]# ll -h
total 189M
-rw-------. 1 root root 1.3K Sep 6 19:20 anaconda-ks.cfg
-rw-rw-rw-. 1 root root 186M Aug 28 2023 jdk-8u211-linux-x64.tar.gz
-rw-r--r--. 1 root root 2.4M Apr 27 2022 redis-6.2.7.tar.gz
#>>> 解压安装包
[root@java ~]# tar xvzf jdk-8u211-linux-x64.tar.gz -C /usr/local/
[root@java ~]# cd /usr/local/
#>>> 更改目录名称
[root@java local]# mv jdk1.8.0_211/ java
#>>> 声明环境变量
[root@java local]# cat >> /etc/profile.d/jdk.sh <<-EOF
#!/bin/bash
# 指定java安装目录
export JAVA_HOME=/usr/local/java
# 用于指定java系统查找命令的路径
export PATH=\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin:\$PATH
EOF
#>>> 重新加载环境变量
[root@java local]# source /etc/profile.d/jdk.sh
#>>> 测试
[root@java local]# java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
Redis安装
- 安装
[root@java ~]# wget https://download.redis.io/releases/redis-6.2.7.tar.gz
[root@java ~]# tar xvzf redis-6.2.7.tar.gz -C /usr/local/
[root@java ~]# cd /usr/local/
[root@java local]# mv redis-6.2.7/ redis
# 安装编译工具
[root@java local]# yum -y install gcc make
[root@java local]# cd redis/
[root@java redis]# make
- 配置修改
#>>> 修改配置文件
[root@java redis]# pwd
/usr/local/redis
[root@java redis]# vim redis.conf
bind 0.0.0.0
daemonize yes
logfile "/var/log/redis.log"
requirepass 12QW!@qw
#>>> 启动redis
[root@java src]# cd src/
[root@java src]# nohup ./redis-server ../redis.conf &
[root@java src]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 5737/./redis-server
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1030/sshd
tcp6 0 0 :::22 :::* LISTEN 1030/sshd
#>>> 测试redis
[root@java src]# ./redis-cli
127.0.0.1:6379> auth 12QW!@qw
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> exit
Jenkins 服务器配置#
因为Jenkins拉取gitlab仓库的代码 需要对其进行打包 并发送到后端的服务器,因此 Jenkins 需要安装打包所需要的工具 (Maven ,jdk11 Tomcat用于运行Jenkins服务 ,nodeJS ,git)
jdk11安装
[root@jenkins ~]# ll -h
-rw-rw-rw-. 1 root root 172M Sep 10 16:15 jdk-11.0.2_linux-x64_bin.tar.gz
[root@jenkins ~]# cd /usr/local/
[root@jenkins local]# mv jdk-11.0.2/ java
[root@jenkins local]# vim /etc/profile #配置环境变量
JAVA_HOME=/usr/local/java
PATH=$JAVA_HOME/bin:$PATH
[root@jenkins local]# source /etc/profile
[root@jenkins local]# java -version
java version "11.0.2" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+7-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+7-LTS, mixed mode)
Tomcat安装以及部署Jenkins
# 官网上已经找不到 可以在网上搜一下
[root@jenkins ~]# ll -h
total 9.3M
-rw-rw-rw-. 1 root root 9.3M Aug 28 2023 apache-tomcat-8.5.45.tar.gz
[root@jenkins ~]# tar xvzf apache-tomcat-8.5.45.tar.gz -C /usr/local/
[root@jenkins ~]# cd /usr/local/
[root@jenkins local]# mv apache-tomcat-8.5.45/ tomcat
[root@jenkins local]# rm -rf tomcat/webapps/*
###获取Jenkins源码包 使用的2.414.3的版本
[root@jenkins local]# cd tomcat/webapps/
[root@jenkins webapps]# wget https://get.jenkins.io/war-stable/2.414.3/jenkins.war
[root@jenkins webapps]# ll -h
total 86M
-rw-r--r--. 1 root root 86M Oct 19 2023 jenkins.war
###启动tomcat
[root@jenkins tomcat]# pwd
/usr/local/tomcat
[root@jenkins tomcat]# ./bin/startup.sh

[root@jenkins tomcat]# yum -y install libXrender libXext libXtst fontconfig
###之后重新tomcat即可
[root@jenkins tomcat]# ./bin/shutdown.sh
[root@jenkins tomcat]# ./bin/startup.sh

###查看密码
[root@jenkins tomcat]# cat /root/.jenkins/secrets/initialAdminPassword
16e6d44ecc494cedac1b0ce159b2332e





nodejs安装
[root@jenkins ~]# ll
-rw-rw-rw-. 1 root root 21605928 Sep 10 16:15 node-v16.13.0-linux-x64.tar.xz
#>>> 解压安装包
[root@jenkins ~]# tar xvf node-v16.13.0-linux-x64.tar.xz -C /usr/local/
[root@jenkins ~]# cd /usr/local/
[root@jenkins local]# mv node-v16.13.0-linux-x64/ nodejs
#>>> 声明环境变量
[root@jenkins local]# vim /etc/profile
JAVA_HOME=/usr/local/java
NODEJS_HOME=/usr/local/nodejs
PATH=$JAVA_HOME/bin:$NODEJS_HOME/bin:$PATH
#>>> 重新加载配置文件
[root@jenkins local]# source /etc/profile
#>>> 测试是否安装成功
[root@jenkins local]# node -v
v16.13.0
[root@jenkins local]# npm -v
8.1.0
安装maven工具
maven编译打包java代码
###准备源码包 兄弟们自行准备
[root@jenkins ~]# ll
total 193396
-rw-rw-rw-. 1 root root 8673123 Sep 10 16:15 apache-maven-3.8.5-bin.tar.gz
#>>> 解压安装包
[root@jenkins ~]# tar xvzf apache-maven-3.8.5-bin.tar.gz -C /usr/local/java/
[root@jenkins ~]# cd /usr/local/java/
[root@jenkins java]# mv apache-maven-3.8.5/ maven
[root@jenkins java]# vim /etc/profile
JAVA_HOME=/usr/local/java
MAVEN_HOME=/usr/local/java/maven
NODEJS_HOME=/usr/local/nodejs
PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$NODEJS_HOME/bin:$PATH
#>>> 重新加载环境变量
[root@nginx local]# source /etc/profile
#>>> 测试使用
[root@jenkins java]# mvn -v
Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
#>>> 修改mvn插件拉取地址
[root@localhost ~]# vim /usr/local/apache-maven-3.9.6/conf/settings.xml
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>

一般在maven安装目录的
/usr/local/apache-maven-3.9.6/conf/settings.xml
,在<mirrors></mirrors>
标签中添加 mirror 子节点
更改项目配置#
#>>> 进入项目目录 我们的项目是在前端的服务器里面拉下来的
[root@nginx ~]# ls
mysql80-community-release-el7-3.noarch.rpm RuoYi-Vue
[root@nginx ~]# cd RuoYi-Vue/ruoyi-admin/src/main/resources/
#>>> 更改数据库连接池
[root@nginx resources]# vim application-druid.yml

#>>> 更改redis连接池
[root@nginx resources]# vim application.yml

项目代码推送到gitlab仓库#
首先准备好我们的gitlab仓库 没有准备的可以参考
gitlab中创建一个项目仓库
gitlab配置#
ssh方式拉取推送代码
####在Nginx静态服务器创建一个密钥对 将公钥配置到gitlab服务
[root@nginx ~]# ssh-keygen #一路回车
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:6cpRZ84NHRlgrQHX3z8PQ1NrCjdIVzQmO1ci/wYTHak root@nginx
The key's randomart image is:
+---[RSA 2048]----+
| ..++o.=B+|
| o..o*++=|
| .o=+=+.|
| ..+ E**.|
| S + +.+.+|
| o = o .oo.|
| . . o . oo|
| . o .|
| o |
+----[SHA256]-----+
[root@nginx ~]# ls .ssh/
id_rsa id_rsa.pub
###将公钥配置到gitlab服务
[root@nginx ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDjAQaGc9zaU5uMMFS/zYf4RJY1srSHWlxO9AADPzxLK/K1EC0GMQFHph9laKv9ztmdEVoK9Y2/vetsA1SCxzIL8bBJ61XA3n4JDVnl3MIDjP3LC4U2lBG+Cj0t53LbiPCPrXfHUnlRCE4aX2SINRTEOqoWoXsUxpfNR6OTN5kHNyecKKJ+EkAKElgLxVFJwUoQqsrsW+dVpQo0U5NwaRn1I6rHbRjtzsJHvjfArumIkmkkzjgXcSVJ4fZFKPxGpzQl6HmPxDIrlxaEWaFInHviytbFbUoZKmfirunX0jd5aw6ujSA/7PuYTIsPZVDuuhHa3pPE3MpMrpetxCHo+5WX root@nginx



[root@nginx ~]# yum -y install git
[root@nginx ~]# git clone git@gitlab.bforest.top:root/ruoyiweb.git
Cloning into 'ruoyiweb'...
The authenticity of host 'gitlab.bforest.top (192.168.13.121)' can't be established.
ECDSA key fingerprint is SHA256:D/FWfaui7s6WUEgnutmPIacldhG59rnk/S1iLIjo1Bc.
ECDSA key fingerprint is MD5:59:07:48:72:e9:2d:a7:b6:0a:2c:3a:e9:40:73:13:7a.
Are you sure you want to continue connecting (yes/no)? yes ##第一次拉取需要输入yes
Warning: Permanently added 'gitlab.bforest.top,192.168.13.121' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (3/3), done.
[root@nginx ~]# ls
mysql80-community-release-el7-3.noarch.rpm RuoYi-Vue ruoyiweb
###将项目复制到本地仓库 再推入远程仓库gitlab
[root@nginx ~]# cp -r RuoYi-Vue/* ruoyiweb/
cp: overwrite ‘ruoyiweb/README.md’? y
[root@nginx ~]# cd ruoyiweb/
###推送之前需要配置本地的信息 自定义名称和邮箱
[root@nginx ruoyiweb]# git config --global user.name "boforest"
[root@nginx ruoyiweb]# git config --global user.email "boforest@163.com"
[root@nginx ruoyiweb]# git add *
[root@nginx ruoyiweb]# git commit -m '原始版本'
[root@nginx ruoyiweb]# git push origin main

http方式拉取推送代码
[root@nginx ~]# git clone https://gitlab.bforest.top/root/ruoyiweb.git

##推送也是和ssh方式一样的步骤
Jenkins服务部署#
Jenkins插件安装#


需要的插件都有
![]()
![]()
![]()
![]()
插件安装后重启一下
![]()
配置全局工具(Maven nodeJS jdk)#

配置JDK11
![]()
配置Maven工具
![]()
配置nodeJS工具
![]()
Jenkins服务器准备密钥对#
这里使用root用户创建
[root@jenkins ~]# ssh-keygen
[root@jenkins ~]# ls /root/.ssh/
id_rsa id_rsa.pub
因为Jenkins需要拉取gitlab的代码 所以我们将Jenkins创建的公钥配置到gitlab服务里
[root@jenkins ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDK/eI5/n5tlhURj7Zhy/7NayeSzBiD4Ew+HRMIxZBBYP3XIS5ZjplJhhCqC8NFHy8DQWrskakB1t/A7CGj9QB27obe/joGRM5Hr0Dx01YNMqA3h0JOMFUqe/1ekbTyARs4x5Z8FTL22OFDLyIRc7y0oluUajz+EJp6btWYgIckhuQzSYEB7T/AncfkNmgd5XBcu7LCkVpEhatj6DqirNjvHg1K6fJH5lIkkiQ7lh2O2bkctliIRZYdmvrYef6BUXrCFialJU/xihS1/mAOqqMDAJIUqvD1Xq5x4mWjb3Nw4PI8xJgGaTBlPsHc6+MLn5kc4Bw+NRbQYlD5jA0ZogLD root@client
Jenkins构建前端项目#
Jenkins服务创建任务
[root@jenkins ~]# cat .ssh/id_rsa
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAyv3iOf5+bZYVEY+2Ycv+zWsnkswYg+BMPh0TCMWQQWD91yEu
WY6ZSYYQqgvDRR8vA0Fq7JGpAdbfwOwho/UAdu6G3v46BkTOR69A8dNWDTKgN4dC
TjBVKnv9XpG08gEbOMeWfBUy9tjhQy8iEXO8tKJblGo8/hCaem7VmICHJIbkM0mB
Ae0/wJ3H5DZoHeVwXLuywpFaRIWrY+g6oqzY7x4NSunyR+ZSJJIkO5Ydjtm5HLZY
iEWWHZr62Hn+gVF6whYmpSVP8YoUtf5gDqqjAwCSFKrw9V6uceJlo29zcODyPMSY
BmkwZT7B3OvjC5+ZHOAcPjUW0GJQ+YwNGaICwwIDAQABAoIBAAbZJ9+zAUrrLEzK
X2nPOwptGgmuzwjr8UaLLpA2Mhaykf3HBcxJrkw3tKo3+V+EnM5sT5Ipm90PBb95
d+0TH+/jPjOZuhVqDteGRxehfJ63XYZiDs+ae9USF8sv+T3M4cE5oo8PHAgN6xOc
LHcQQ4aIj7RjHSmpH70Pri8V7vlBcF/k9Hj1f5oqadmdT7SzkLB87gavRxt9mFhT
OPxXKNjLWOQXlFNRCc+oSvREdY6wOKFLScMlOP9dNZXLFvz0BOW0X0hQiVnsgTqW
Rz2CJKdxO8f5yCFJyF0cagqGBImsiXXZGEhO5aMP78gSDgvM4S2M/RZjHES7l+Xt
En+fe+kCgYEA6yyzP1sTFJnz5thqjLeuUaDXhc8BI8Vlhw1fEvnyNhUGdC+MbwzB
DjfsG5RMHm+Xmsb2bQ3ztJBHytTvffUgyDd2jnJ02xwy/AD7rxqCQAvHe4iUjcoT
AF8VyD8iPkGklREfHe1R4W6HHHDvnlDW4NVa6riPvXrMTFSbFfSD3HUCgYEA3Pec
0E75mNaJ67Htvq7lj/cZ9LmFHyKIQF3+/N6NV7aGF9cdFoVv7oKxip1mRLEOjrPG
vp5ySMOaofIYXRzN80wRhzbDQI+njJjQ7H3lrQAJIJikjwseGeGd0fccG6G8/DbQ
L7eyANBTgq+BwTcHl+z1FVfFsVlOnygg94cS21cCgYEAhPGoAtDBYIwHTSBaW2Ia
sRpzu7jhtA8K7eWpMVkKi3gnRdb7VGupVxhV6OFUhoAe++gttkiE1DYb35WwLUw9
U/HGm5AobxTp3XvQy5P4vavrAPKcx+rMAxG9ho3qFbeWCo67QHfAKegJiRJu4thg
IIl78+SRnVOl2iCZ6zdms2ECgYEAmuZh4Y1bX48VxEpI9aE5gECiy3G6JmdYyHac
J7wDrXdgbRn5ZC5KlxK7TwakCIduQw83xazhRK0Km3hRKATnQyUSLI1xNrL9q4v8
+awP88TQoS8gPL54bYBB2Ey4QY6SIuRx8OF/QR7JTBWoij//bLtJ25paFccbXGsP
ITZpO6UCgYEA5a5nH6+I+/YoXnAOHH6GrsCq/VGQzt3czFolt2mF5pB0XwrR9j7N
C5eCR0UNvMu+5K+C4T2x1TNFPpAc0pRhs2zpW5g00nJCs38q1mf5rI2+5g7WLDoL
zkwaWgqJay3TauxKbv2SKCb8y/QlyW7CMAnRIbKk3KnHWDuIgByTf9o=
-----END RSA PRIVATE KEY-----
测试拉取到Jenkins中
###在Jenkins服务器中先拉取一次 因为第一次拉取需要输入一个yes 如果不拉取一次可能会报错
[root@jenkins ~]# yum -y install git
[root@jenkins ~]# git clone git@gitlab.bforest.top:root/ruoyiweb.git
将Jenkins服务器公钥发送到Nginx服务器
[root@jenkins workspace]# ssh-copy-id root@192.168.13.113
##输入Nginx服务器的用户名root和密码
配置静态web服务器(Nginx)
#>>> 创建日志目录
[root@nginx ~]# mkdir -p /opt/project/ruoyi/logs
#>>> 创建前端项目存放目录
[root@nginx ~]# mkdir -p /ruoyi/ruoyi-ui
#>>> nginx配置文件准备
[root@nginx ~]# vim /etc/nginx/conf.d/default.conf
server {
location / {
root /ruoyi/ruoyi-ui/dist;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080/;
}
}
[root@nginx ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@nginx ~]# systemctl restart nginx
Jenkins前端打包服务配置
![]()
![]()
![]()
cd ruoyi-ui/
npm install -registry=http://registry.npmmirror.com
npm run build:prod
tar cvzf dist.tar.gz dist/![]()
![]()
cd /ruoyi/ruoyi-ui/
tar xvzf dist.tar.gz
chmod 755 dist -R![]()
![]()
访问Nginx进行测试
![]()
前端项目打包完成!
Jenkins构建后端项目#
后端应用服务器配置#
###修改Nginx的配置文件 将动态请求转发到后端服务器
[root@nginx ~]# vim /etc/nginx/conf.d/default.conf

###创建Jenkins代码发送的位置
[root@java local]# mkdir /opt/java
###写一个执行脚本 用于执行后端代码
[root@java java]# vim /opt/java/java1.sh
#!/bin/bash
ruoyi_pid=`ps -ef|grep "ruoyi-admin"|grep -v "grep"|awk '{print $2}'`
if [[ $ruoyi_pid != "" ]];then
echo "若依后端服务PID: $ruoyi_pid"
kill -15 $ruoyi_pid && echo "若依后端服务已关闭"
nohup /usr/local/java/bin/java -jar /opt/java/ruoyi-admin.jar &
if [ $? -eq 0 ];then
echo "若依后端服务已重新启动"
else
echo "若依后端服务重启失败"
fi
else
nohup /usr/local/java/bin/java -jar /opt/java/ruoyi-admin.jar &
if [ $? -eq 0 ];then
echo "若依后端服务已启动"
else
echo "若依后端服务启动失败"
fi
fi
###给一个执行权限
[root@java java]# chmod +x java1.sh
Jenkins公钥发送到后端应用服务器#
[root@jenkins workspace]# ssh-copy-id root@192.168.13.122
#输入后端服务器的root用户和密码
Jenkins服务后端配置#






测试访问

Jenkins配置钉钉机器人通知#







参数化构建项目#
参数化构建主要是便于我们进行回滚操作,在代码有错误时,可以快速回滚到一个稳定的版本
主要有两种方式
修订号方式
—修订号方式需要后端人员在推送代码的时候,做好备注信息,才便于我们进行选择
tag打标签模式
—tag打标签模式也需要后端人员推送代码时打好标签,做好备注,才便于我们观察进行选择
参数化构建项目(修订号方式)#
配置Git参数选项




参数化构建前端项目(tag标签)#
###与修订号的方式相同




模拟前端开发修改并提交代码#
[root@nginx ruoyi-ui]# pwd
/root/ruoyiweb/ruoyi-ui
[root@nginx ruoyi-ui]# vim src/views/index.vue

[root@nginx ruoyiweb]# git add *
[root@nginx ruoyiweb]# git commit -m "2000 20000"
[root@nginx ruoyiweb]# git tag -a 'v1.1.0' -m '2000 20000'
[root@nginx ruoyiweb]# git tag
v1.1.0
[root@nginx ruoyiweb]# git push origin v1.1.0
Counting objects: 12, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 630 bytes | 0 bytes/s, done.
Total 7 (delta 5), reused 0 (delta 0)
To git@10.8.151.25:root/ruoyi-vue.git
* [new tag] v1.1.0 -> v1.1.0

构建测试#

查看构建结果#

版本切换测试#
前端继续更新提交代码
[root@nginx-mysql ruoyi-ui]# pwd
/tmp/ruoyi-vue/ruoyi-ui
[root@nginx-mysql ruoyi-ui]# vim src/views/index.vue

[root@nginx ruoyiweb]# vim ruoyi-ui/src/views/index.vue
[root@nginx ruoyiweb]# git add *
[root@nginx ruoyiweb]# git commit -m 'aliyun tengxunyun'
[root@nginx ruoyiweb]# git tag -a 'v1.1.1' -m 'aliyun tengxunyun'
[root@nginx ruoyiweb]# git push origin v1.1.1
[root@nginx ruoyiweb]# git tag
v1.1.0
v1.1.1


构建完成之后访问

选择上个版本回退

再次访问

【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 我与微信审核的“相爱相杀”看个人小程序副业
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· spring官宣接入deepseek,真的太香了~