更新 持续集成-交付-发布-项目.md
This commit is contained in:
parent
d59c557809
commit
a95b0fe5fa
413
持续集成-交付-发布-项目.md
413
持续集成-交付-发布-项目.md
|
@ -1,207 +1,206 @@
|
||||||
<h1><center>持续集成-交付-发布-项目</center></h1>
|
<h1><center>持续集成-交付-发布-项目</center></h1>
|
||||||
|
|
||||||
**作者:行癫(盗版必究)**
|
|
||||||
|
------
|
||||||
------
|
|
||||||
|
## 一:Jenkins部署
|
||||||
## 一:Jenkins部署
|
|
||||||
|
#### 1.安装插件
|
||||||
#### 1.安装插件
|
|
||||||
|
```shell
|
||||||
```shell
|
• Maven插件 Maven Integration plugin
|
||||||
• Maven插件 Maven Integration plugin
|
• 发布插件 Deploy to container Plugin
|
||||||
• 发布插件 Deploy to container Plugin
|
需要安装插件如下:
|
||||||
需要安装插件如下:
|
安装插件Deploy to container ---支持自动化代码部署到tomcat容器
|
||||||
安装插件Deploy to container ---支持自动化代码部署到tomcat容器
|
Git 插件 可能已经安装
|
||||||
Git 插件 可能已经安装
|
Maven Integration :jenkins利用Maven编译,打包所需插件
|
||||||
Maven Integration :jenkins利用Maven编译,打包所需插件
|
Publish Over SSH :通过ssh连接
|
||||||
Publish Over SSH :通过ssh连接
|
```
|
||||||
```
|
|
||||||
|
#### 2.安装过程
|
||||||
#### 2.安装过程
|
|
||||||
|
系统管理--->插件管理---->可选插件--->过滤Deploy to container---->勾选--->直接安装
|
||||||
系统管理--->插件管理---->可选插件--->过滤Deploy to container---->勾选--->直接安装
|
|
||||||
|
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220627235514357.png" alt="image-20220627235514357" style="zoom:50%;" />
|
||||||
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220627235514357.png" alt="image-20220627235514357" style="zoom:50%;" />
|
|
||||||
|
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220627235607259.png" alt="image-20220627235607259" style="zoom:50%;" />
|
||||||
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220627235607259.png" alt="image-20220627235607259" style="zoom:50%;" />
|
|
||||||
|
#### 3.配置SSH
|
||||||
#### 3.配置SSH
|
|
||||||
|
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220627235758575.png" alt="image-20220627235758575" style="zoom:50%;" />
|
||||||
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220627235758575.png" alt="image-20220627235758575" style="zoom:50%;" />
|
|
||||||
|
![image-20220627235903284](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220627235903284.png)
|
||||||
![image-20220627235903284](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220627235903284.png)
|
|
||||||
|
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628000008461.png" alt="image-20220628000008461" style="zoom:50%;" />
|
||||||
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628000008461.png" alt="image-20220628000008461" style="zoom:50%;" />
|
|
||||||
|
注意:
|
||||||
注意:
|
|
||||||
|
key:指的是jenkins服务器用哪个用户去远程连接程序服务器就是那个用户的私钥。(记得做免密 jenkins---> web-server)
|
||||||
key:指的是jenkins服务器用哪个用户去远程连接程序服务器就是那个用户的私钥。(记得做免密 jenkins---> web-server)
|
|
||||||
|
![img](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/K2KQE6euhjvTIomINthtvg.png)
|
||||||
![img](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/K2KQE6euhjvTIomINthtvg.png)
|
|
||||||
|
#### 4.配置jdk,maven,git
|
||||||
#### 4.配置jdk,maven,git
|
|
||||||
|
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628000213404.png" alt="image-20220628000213404" style="zoom:50%;" />
|
||||||
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628000213404.png" alt="image-20220628000213404" style="zoom:50%;" />
|
|
||||||
|
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628000256756.png" alt="image-20220628000256756" style="zoom:50%;" />
|
||||||
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628000256756.png" alt="image-20220628000256756" style="zoom:50%;" />
|
|
||||||
|
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628000323472.png" alt="image-20220628000323472" style="zoom:50%;" />
|
||||||
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628000323472.png" alt="image-20220628000323472" style="zoom:50%;" />
|
|
||||||
|
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628000358938.png" alt="image-20220628000358938" style="zoom:50%;" />
|
||||||
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628000358938.png" alt="image-20220628000358938" style="zoom:50%;" />
|
|
||||||
|
## 二:构建发布任务
|
||||||
## 二:构建发布任务
|
|
||||||
|
#### 1.创建maven项目
|
||||||
#### 1.创建maven项目
|
|
||||||
|
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628000510980.png" alt="image-20220628000510980" style="zoom:50%;" />
|
||||||
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628000510980.png" alt="image-20220628000510980" style="zoom:50%;" />
|
|
||||||
|
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628000547600.png" alt="image-20220628000547600" style="zoom:50%;" />
|
||||||
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628000547600.png" alt="image-20220628000547600" style="zoom:50%;" />
|
|
||||||
|
#### 2.配置项目
|
||||||
#### 2.配置项目
|
|
||||||
|
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628000721842.png" alt="image-20220628000721842" style="zoom:50%;" />
|
||||||
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628000721842.png" alt="image-20220628000721842" style="zoom:50%;" />
|
|
||||||
|
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628000814797.png" alt="image-20220628000814797" style="zoom:50%;" />
|
||||||
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628000814797.png" alt="image-20220628000814797" style="zoom:50%;" />
|
|
||||||
|
https://github.com/bingyue/easy-springmvc-maven
|
||||||
https://github.com/bingyue/easy-springmvc-maven
|
|
||||||
|
![img](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/vxtF-uRF9X71FkT1Ac_JIA.png)
|
||||||
![img](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/vxtF-uRF9X71FkT1Ac_JIA.png)
|
|
||||||
|
注意:
|
||||||
注意:
|
|
||||||
|
新版本需要将默认分支改为main
|
||||||
新版本需要将默认分支改为main
|
|
||||||
|
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628003247070.png" alt="image-20220628003247070" style="zoom:50%;" />
|
||||||
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628003247070.png" alt="image-20220628003247070" style="zoom:50%;" />
|
|
||||||
|
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628003459003.png" alt="image-20220628003459003" style="zoom:50%;" />
|
||||||
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628003459003.png" alt="image-20220628003459003" style="zoom:50%;" />
|
|
||||||
|
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628003538519.png" alt="image-20220628003538519" style="zoom:50%;" />
|
||||||
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628003538519.png" alt="image-20220628003538519" style="zoom:50%;" />
|
|
||||||
|
调用mave命令
|
||||||
调用mave命令
|
|
||||||
|
(clean package -Dmaven.test.skip = true)
|
||||||
(clean package -Dmaven.test.skip = true)
|
|
||||||
|
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628003556160.png" alt="image-20220628003556160" style="zoom:50%;" />
|
||||||
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628003556160.png" alt="image-20220628003556160" style="zoom:50%;" />
|
|
||||||
|
保存:
|
||||||
保存:
|
|
||||||
|
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628003642699.png" alt="image-20220628003642699" style="zoom:50%;" />
|
||||||
<img src="https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20220628003642699.png" alt="image-20220628003642699" style="zoom:50%;" />
|
|
||||||
|
#### 3.发布服务器部署
|
||||||
#### 3.发布服务器部署
|
|
||||||
|
```shell
|
||||||
```shell
|
[root@java-server ~]# mkdir -p /data/application
|
||||||
[root@java-server ~]# mkdir -p /data/application
|
上传jdk
|
||||||
上传jdk
|
[root@java-server ~]# tar xzf jdk-8u191-linux-x64.tar.gz -C /usr/local/
|
||||||
[root@java-server ~]# tar xzf jdk-8u191-linux-x64.tar.gz -C /usr/local/
|
[root@java-server ~]# cd /usr/local/
|
||||||
[root@java-server ~]# cd /usr/local/
|
[root@java-server local]# mv jdk1.8.0_191/ java
|
||||||
[root@java-server local]# mv jdk1.8.0_191/ java
|
下载tomcat
|
||||||
下载tomcat
|
[root@java-server ~]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.42/bin/apache-tomcat-8.5.42.tar.gz
|
||||||
[root@java-server ~]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.42/bin/apache-tomcat-8.5.42.tar.gz
|
[root@java-server ~]# tar xzf apache-tomcat-8.5.42.tar.gz -C /data/application/
|
||||||
[root@java-server ~]# tar xzf apache-tomcat-8.5.42.tar.gz -C /data/application/
|
[root@java-server ~]# cd /data/application/
|
||||||
[root@java-server ~]# cd /data/application/
|
[root@java-server application]# mv apache-tomcat-8.5.42/ tomcat
|
||||||
[root@java-server application]# mv apache-tomcat-8.5.42/ tomcat
|
设置环境变量
|
||||||
设置环境变量
|
[root@java-server ~]# vim /etc/profile
|
||||||
[root@java-server ~]# vim /etc/profile
|
export JAVA_HOME=/usr/local/java
|
||||||
export JAVA_HOME=/usr/local/java
|
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
|
||||||
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
|
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
|
||||||
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
|
export TOMCAT_HOME=/data/application/tomcat
|
||||||
export TOMCAT_HOME=/data/application/tomcat
|
[root@java-server ~]# source /etc/profile
|
||||||
[root@java-server ~]# source /etc/profile
|
测试:
|
||||||
测试:
|
[root@java-server ~]# java -version
|
||||||
[root@java-server ~]# java -version
|
java version "1.8.0_191"
|
||||||
java version "1.8.0_191"
|
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
|
||||||
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
|
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
|
||||||
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
|
删除tomcat默认发布目录下面的内容:
|
||||||
删除tomcat默认发布目录下面的内容:
|
[root@java-server ~]# rm -rf /data/application/tomcat/webapps/*
|
||||||
[root@java-server ~]# rm -rf /data/application/tomcat/webapps/*
|
[root@java-server ~]# cd /data/application/tomcat/webapps/
|
||||||
[root@java-server ~]# cd /data/application/tomcat/webapps/
|
[root@java-server webapps]# ls
|
||||||
[root@java-server webapps]# ls
|
创建目录和脚本:
|
||||||
创建目录和脚本:
|
[root@java-server ~]# mkdir /opt/script #创建脚本目录
|
||||||
[root@java-server ~]# mkdir /opt/script #创建脚本目录
|
[root@java-server ~]# vim app-jenkins.sh #创建脚本
|
||||||
[root@java-server ~]# vim app-jenkins.sh #创建脚本
|
#!/usr/bin/bash
|
||||||
#!/usr/bin/bash
|
#本脚本适用于jenkins持续集成,实现备份war包到代码更新上线!使用时请注意全局变量。
|
||||||
#本脚本适用于jenkins持续集成,实现备份war包到代码更新上线!使用时请注意全局变量。
|
#================
|
||||||
#================
|
#Defining variables
|
||||||
#Defining variables
|
export JAVA_HOME=/usr/local/java
|
||||||
export JAVA_HOME=/usr/local/java
|
webapp_path="/data/application/tomcat/webapps"
|
||||||
webapp_path="/data/application/tomcat/webapps"
|
tomcat_run="/data/application/tomcat/bin"
|
||||||
tomcat_run="/data/application/tomcat/bin"
|
updata_path="/data/update/`date +%F-%T`"
|
||||||
updata_path="/data/update/`date +%F-%T`"
|
backup_path="/data/backup/`date +%F-%T`"
|
||||||
backup_path="/data/backup/`date +%F-%T`"
|
tomcat_pid=`ps -ef | grep tomcat | grep -v grep | awk '{print $2}'`
|
||||||
tomcat_pid=`ps -ef | grep tomcat | grep -v grep | awk '{print $2}'`
|
files_dir="easy-springmvc-maven"
|
||||||
files_dir="easy-springmvc-maven"
|
files="easy-springmvc-maven.war"
|
||||||
files="easy-springmvc-maven.war"
|
job_path="/root/upload"
|
||||||
job_path="/root/upload"
|
|
||||||
|
#Preparation environment
|
||||||
#Preparation environment
|
echo "Creating related directory"
|
||||||
echo "Creating related directory"
|
mkdir -p $updata_path
|
||||||
mkdir -p $updata_path
|
mkdir -p $backup_path
|
||||||
mkdir -p $backup_path
|
|
||||||
|
echo "Move the uploaded war package to the update 2directory"
|
||||||
echo "Move the uploaded war package to the update 2directory"
|
mv $job_path/$files $updata_path
|
||||||
mv $job_path/$files $updata_path
|
|
||||||
|
echo "========================================================="
|
||||||
echo "========================================================="
|
cd /opt
|
||||||
cd /opt
|
echo "Backing up java project"
|
||||||
echo "Backing up java project"
|
if [ -f $webapp_path/$files ];then
|
||||||
if [ -f $webapp_path/$files ];then
|
tar czf $backup_path/`date +%F-%H`.tar.gz $webapp_path
|
||||||
tar czf $backup_path/`date +%F-%H`.tar.gz $webapp_path
|
if [ $? -ne 0 ];then
|
||||||
if [ $? -ne 0 ];then
|
echo "打包失败,自动退出"
|
||||||
echo "打包失败,自动退出"
|
exit 1
|
||||||
exit 1
|
else
|
||||||
else
|
echo "Checking if tomcat is started"
|
||||||
echo "Checking if tomcat is started"
|
if [ -n "$tomcat_pid" ];then
|
||||||
if [ -n "$tomcat_pid" ];then
|
kill -9 $tomcat_pid
|
||||||
kill -9 $tomcat_pid
|
if [ $? -ne 0 ];then
|
||||||
if [ $? -ne 0 ];then
|
echo "tomcat关闭失败,将会自动退出"
|
||||||
echo "tomcat关闭失败,将会自动退出"
|
exit 2
|
||||||
exit 2
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
cd $webapp_path
|
||||||
cd $webapp_path
|
rm -rf $files && rm -rf $files_dir
|
||||||
rm -rf $files && rm -rf $files_dir
|
cp $updata_path/$files $webapp_path
|
||||||
cp $updata_path/$files $webapp_path
|
cd /opt
|
||||||
cd /opt
|
$tomcat_run/startup.sh
|
||||||
$tomcat_run/startup.sh
|
sleep 5
|
||||||
sleep 5
|
echo "显示tomcat的pid"
|
||||||
echo "显示tomcat的pid"
|
echo "`ps -ef | grep tomcat | grep -v grep | awk '{print $2}'`"
|
||||||
echo "`ps -ef | grep tomcat | grep -v grep | awk '{print $2}'`"
|
echo "tomcat startup"
|
||||||
echo "tomcat startup"
|
echo "请手动查看tomcat日志。脚本将会自动退出"
|
||||||
echo "请手动查看tomcat日志。脚本将会自动退出"
|
fi
|
||||||
fi
|
else
|
||||||
else
|
echo "Checking if tomcat is started"
|
||||||
echo "Checking if tomcat is started"
|
if [ -n "$tomcat_pid" ];then
|
||||||
if [ -n "$tomcat_pid" ];then
|
kill -9 $tomcat_pid
|
||||||
kill -9 $tomcat_pid
|
if [ $? -ne 0 ];then
|
||||||
if [ $? -ne 0 ];then
|
echo "tomcat关闭失败,将会自动退出"
|
||||||
echo "tomcat关闭失败,将会自动退出"
|
exit 2
|
||||||
exit 2
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
cp $updata_path/$files $webapp_path
|
||||||
cp $updata_path/$files $webapp_path
|
$tomcat_run/startup.sh
|
||||||
$tomcat_run/startup.sh
|
sleep 5
|
||||||
sleep 5
|
echo "显示tomcat的pid"
|
||||||
echo "显示tomcat的pid"
|
echo "`ps -ef | grep tomcat | grep -v grep | awk '{print $2}'`"
|
||||||
echo "`ps -ef | grep tomcat | grep -v grep | awk '{print $2}'`"
|
echo "tomcat startup"
|
||||||
echo "tomcat startup"
|
echo "请手动查看tomcat日志。脚本将会自动退出"
|
||||||
echo "请手动查看tomcat日志。脚本将会自动退出"
|
fi
|
||||||
fi
|
[root@java-server ~]# vim app-jenkins.sh
|
||||||
[root@java-server ~]# vim app-jenkins.sh
|
脚本内容在后面
|
||||||
脚本内容在后面
|
[root@java-server ~]# chmod +x app-jenkins.sh #添加执行权限
|
||||||
[root@java-server ~]# chmod +x app-jenkins.sh #添加执行权限
|
[root@java-server ~]# mv app-jenkins.sh /opt/script/
|
||||||
[root@java-server ~]# mv app-jenkins.sh /opt/script/
|
```
|
||||||
```
|
|
||||||
|
#### 4.开始构建任务
|
||||||
#### 4.开始构建任务
|
|
||||||
|
![img](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/3CiCTOTQ2tZ0n6pHy_9N8Q.png)
|
||||||
![img](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/3CiCTOTQ2tZ0n6pHy_9N8Q.png)
|
|
||||||
|
![img](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/8Zvu0JAjLexNZw4McJs9mw.png)
|
||||||
![img](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/8Zvu0JAjLexNZw4McJs9mw.png)
|
|
||||||
|
![img](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/xCOkP5CTpof6CmgXsPzrDQ.png)
|
||||||
![img](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/xCOkP5CTpof6CmgXsPzrDQ.png)
|
|
||||||
|
![img](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/vGcPCV6C-Ro_9NcJONgW7g.png)
|
||||||
![img](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/vGcPCV6C-Ro_9NcJONgW7g.png)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue