1: 添加添加Active Choices Parameter 插件
##set color##
echoRed() { echo $'\e[0;31m'"$1"$'\e[0m'; }
echoGreen() { echo $'\e[0;32m'"$1"$'\e[0m'; }
echoYellow() { echo $'\e[0;33m'"$1"$'\e[0m'; }
##set 环境变量##
source /etc/profile
jenkins_home=/dockerdata/jenkins_home
if [ $mode == "Deploy" ];then
datetime=`date "+%Y%m%d%H%M"`
if [ $status == "test1" ];then
echoRed "您选择执行的是test1服务器,开始远程备份!"
sshpass -f /dockerdata/xc/prokey/test1 ssh root@172.19.14.246 "mkdir -p /var/www/app_m/web2/bak/$datetime && cp -r /var/www/app_m/web2/sancell-shop-app-mobile /var/www/app_m/web2/bak/$datetime && rm -rf /var/www/app_m/web2/sancell-shop-app-mobile/* "
cd $jenkins_home/workspace/pro-sancell-shop-app-mobile-test/activeproduct
cp -r $jenkins_home/workspace/pro-sancell-shop-app-mobile-test/activeproduct $jenkins_home/jobs/pro-sancell-shop-app-mobile-test/builds/${version}/
sshpass -f /dockerdata/xc/prokey/test1 scp -r * root@172.19.14.246:/var/www/app_m/web2/sancell-shop-app-mobile/
echoRed "发布结束!"
fi
fi
if [ $mode == "RollBACK" ];then
echo "$mode version=$version"
if [ $status == "test1" ];then
echoRed "您选择回滚的是test1服务器,回滚开始!"
sshpass -f /dockerdata/xc/prokey/test1 ssh root@172.19.14.246 " rm -rf /var/www/app_m/web2/sancell-shop-app-mobile/* "
cd $jenkins_home/jobs/pro-sancell-shop-app-mobile-test/builds/${version}/
sshpass -f /dockerdata/xc/prokey/test1 scp -r activeproduct/* root@172.19.14.246:/var/www/app_m/web2/sancell-shop-app-mobile/
echoRed "回滚结束!"
fi
fi
参考:https://www.jianshu.com/p/af5fecaa8357
https://www.liangzl.com/get-article-detail-134977.html