Jenkins--docker自动部署springboot

cd /root/.jenkins/workspace/iids-msa-eureka/iids/iids-msa-eureka
version=`awk '/[^<]+<\/version>/{gsub(/|<\/version>/,"",$1);print $1;exit;}' pom.xml`

echo '================开始构建新镜像================'
sudo docker build -t iids-msa-eureka:$version .
imageId=$(docker images | grep "none" | awk '{print $3}')
if [ -z "$imageId" ]; then 
    echo "没有none镜像" 
fi
if [ -n "$imageId" ]; then 
    echo "删除none相关镜像" 
    sudo docker rmi $imageId
fi

echo '================开始推送镜像================'
sudo docker login --username=账号 --password=密码 registry.cn-shanghai.aliyuncs.com
sudo docker tag iids-msa-eureka:$version iids-msa-eureka:$version
sudo docker push registry.cn-shanghai.aliyuncs.com/tct-iids/iids-msa-eureka:$version
ssh [email protected] -tt << remotessh

echo '================开始远程操作================'
sudo docker login --username=账号 --password=密码  registry.cn-shanghai.aliyuncs.com
sudo docker pull registry.cn-shanghai.aliyuncs.com/tct-iids/iids-msa-eureka:$version
sudo docker stop iids-msa-eureka
sudo docker rm iids-msa-eureka
sudo docker run -d -p 7001:7001 --network host --restart=always --name iids-msa-eureka registry.cn-shanghai.aliyuncs.com/tct-iids/iids-msa-eureka:$version
echo "iids-msa-eureka容器已启动,当前版本 $version" 
echo "finished!" 
exit 
###结尾
remotessh 
echo '================退出远程服务器,自动化部署完成================'

你可能感兴趣的:(运维,Docker)