1、选择构建一个项目
2、配置发布模块
3、配置执行shell脚本。
#!/bin/bash
time=$(date +%Y%m%d%H%M)
export PATH="/opt/software/zx/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/tomcat/bin:/home/tomcat/tools/maven/apache-maven-3.6.3/bin"
export DOCKER_HOST="tcp://192.168.15.129:2375"
cd /home/tomcat/codes/egrant-equipment
git pull
cd /home/tomcat/codes/egrant-equipment/egrant-common
mvn clean install
cd /home/tomcat/codes/egrant-equipment
echo 开始打包 $service
pwd
if [ $service == 所有 ] ; then
echo 打包微服务模块all
elif [ $service = 'egrant-auth' ] || [ $service = 'egrant-gateway' ] ; then
echo 打包授权-网关auth
cd $service
elif [ $service = 'egrant-resource' ] || [ $service = 'egrant-log' ] ; then
echo 打包资源日志ops===$service
cd /home/tomcat/codes/egrant-equipment/egrant-ops-api
mvn clean install
cd /home/tomcat/codes/egrant-equipment/egrant-ops/$service
else
echo 打包微服务模块==$service
cd /home/tomcat/codes/egrant-equipment/egrant-service-api
mvn clean install
cd /home/tomcat/codes/egrant-equipment/egrant-service/$service
fi
pwd
mvn clean package -U -Dmaven.test.skip=true dockerfile:build
echo ===15.6 jenkins 打包完成
echo 当前操作:${push}
if [ $push = 'true' ] ; then
mvn dockerfile:push
echo 推送镜像完成
fi
scp -r /home/tomcat/codes/egrant-equipment/script/docker/app/docker-compose.yml root@192.168.15.129:/home/equipment/docker/app/docker-compose.yml
echo ===连接到15.129
servicet=${service}
if [ ${service} == 所有 ] ; then
echo 打包微服务所有模块
servicet=``
else
echo 执行模块==$servicet
fi
ssh root@192.168.15.129 -tt << eeooff
cd /home/equipment/docker/app/
echo 模块===${servicet}
###先停止服务
docker-compose --compatibility stop ${servicet}
## 删除服务
docker-compose rm -f ${servicet}
## 重启服务
docker-compose --compatibility up -d ${servicet}
## 删除none镜像
docker rmi $(docker images -f "dangling=true" -q)> /dev/null 2>&1
#####执行完毕
sleep 15
exit ###退出远程机器
eeooff ###结尾哦
echo '================结束远程启动================'
echo "success"