一般收到的发布邮件如下2种
直接邮件里复制 并黏贴到linux的2.txt文件中
cat 出来 没有这个<200b>
通过脚本筛选发布项目名 并去掉版本号
执行发布脚本如下
模拟基础模块部署失败的情况 会停止后面的部署
最后的脚本如下complie.sh
#!/bin/bash funcprepare(){ i=0 while [ $i -le 2 ] do read -r -p "是否执行过发布前脚本? [Y/n] " input
case $input in [yY][eE][sS]|[yY]) echo "Yes" let i++ ;;
[nN][oO]|[nN]) echo "No" exit ;;
*) echo "请确认是否执行过发布前脚本..." ;; esac done }
funcomplie(){ echo "[tags]进入funcomplie函数" for i in `cat complie.txt | tr -d '[0-9]' |tr -d ' ' |tr -d '.' |grep -v '^$'` do if [[ "new-test-base" =~ "$i" ]] || [[ "new-test-sdk" =~ "$i" ]];then #if [ "new-ac-parent" == *$i* ] || [ "new-ac-sdk" == *$i* ];then echo "[tags]即将部署项目 $i" curl -s -u jiaminxu:1161350de54c880d5b08c2616a1b6c7243 -X POST "http://192.168.10.204:8080/job/new-$i/buildWithParameters?token=123456 " -d 'env=master' sleep 10 funcbase else echo "[tags]部署非基础模块: $i" curl -s -u jiaminxu:1161350de54c880d5b08c2616a1b6c7243 -X POST "http://192.168.10.204:8080/job/new-$i/buildWithParameters?token=123456 " -d 'env=master&deploy_step=Deploy' fi done }
funcbase(){ echo "[tags]进入funcbase函数" echo i:$i complie_result=`curl -s -u jiaminxu:1161350de54c880d5b08c2616a1b6c7243 -X POST "http://192.168.10.204:8080/job/new-$i/lastBuild/api/json?token=123456 "|grep -Po '"result":".*?"'|awk -F : '{print $2}'|sed 's/\"/ /'g` echo 项目名 $complie_result time=0
while [ "$complie_result" == "" ] do #echo "部署编译完成 $complie_result " echo "编译还在进行中" sleep 5 let time+=5 echo 项目编译时间 $time complie_result=`curl -s -u jiaminxu:1161350de54c880d5b08c2616a1b6c7243 -X POST "http://192.168.10.204:8080/job/new-$i/lastBuild/api/json?token=123456 "|grep -Po '"result":".*?"'|awk -F : '{print $2}'|sed 's/\"/ /'g` echo 项目名 $complie_result done #echo "编译还在进行中" echo "部署编译完成 $complie_result " result=$(echo $complie_result |grep "SUCCESS") echo 项目名 $complie_result
if [[ "$result" != "" ]] then echo "部署结果包含success 编译完成 " else echo "编译失败" exit 7 fi }
echo "[tags] 开始执行编译 complie" echo "[tags] 开始执行编译 complie" echo "[tags] 开始执行编译 complie"
for i in `cat complie.txt | tr -d '[0-9]' |tr -d ' ' |tr -d '.' |grep -v '^$' ` #for i in `cat 2.txt | tr -d '[0-9]' |tr -d ' ' |tr -d '.' |grep -v '^$'|grep 'core' ` #for i in `cat 2.txt | tr -d '[0-9]' |tr -d ' ' |tr -d '.' |grep -v '^$'|grep -v 'core' ` do #echo "[tags]原发布项目: $i" echo "[tags]处理过后发布的项目: ${i%*-}"
done
funcprepare funcomplie |
complie.txt如下 里面写需要发布的项目
test-base test-sdk test-api |