1.查看工程编译打包是否自动完成
#!/bin/bash
# 将本地命令行运行job
#curl -n -X POST http://XXX:8089/job/scev6/buildWithParameters --user xxxx:1234abcd --data cp_branch='stage-mom'
#获取jenkins 控制台日志
#curl -n -X POST http://XXX:8089/job/scev6/$job_number/consoleText --user xxxx:1234abcd
#使用列表for循环所要运行的job名,按照列表里先后顺序执行,不可更改
for variable in scev6 scev6-multilang
do
#获取下一次构建编号
job_number=`curl --silent http://XXX:8089/job/$variable/api/json --user xxx:1234abcd |jq --raw-output '.nextBuildNumber'`
#执行job,分支选择stage-mom,也即是10.79.69.21
curl -n -X POST http://XXX:8089/job/$variable/buildWithParameters --user XXX:1234abcd --data cp_branch='stage'
#查询job状态最多循环执行5次
for i in `seq 1 5`
do
#查询间隔时间60s,启动下一个job,最长间隔5分钟
sleep 60
#获取当前job运行结果
##job_result=$(curl --silent http://XXX:8089/job/$variable/lastBuild/api/json --user XXX:1234abcd |jq --raw-output '.result')
job_result=`curl --silent http://XXX:8089/job/$variable/$job_number/api/json --user XXX:1234abcd |jq --raw-output '.result'`
echo "=================第$i次检测当前job:${variable},job编号:$job_number,job运行状态: $job_result ====================================="
if [[ $job_result = "SUCCESS" ]];then
echo "=================job:$variable构建完成,运行下一个 ==================="
break
elif [[ $job_result = "FAILURE" ]] || [[ $job_result = "ABORTED" ]];then
echo "=================job:$variable构建失败,运行下一个 ==================="
break
else [[ $job_result = "null" ]]
echo "job_$variable构建中......"
fi
done
done
2.上传打包后的工程到腾讯云服务器
#!/bin/bash
vdate=`date +'%Y%m%d%H%M%S'`
tg="v${vdate}_${BUILD_NUMBER}"
port=22
target=root@xxx
#pwd="cobbler"
pwd=/home/devops/.ssh/id_rsa
cmd="sudo rsync -avP -e \"ssh -i /root/.ssh/id_rsa\" /mnt/scev6/war/ root@xxx:/mnt/scev6/war/ --include=/* --include=*.jar --include=*.war --exclude=*"
ssh -p $port -i $pwd $target "$cmd"
#ssh -p 22 -i /home/devops/.ssh/id_rsa momuser@xxx
echo '传输文件到腾讯云服务器(124.223.62.51)上完成......'
3.启动服务
#!/bin/bash vdate=`date +'%Y%m%d%H%M%S'` tg="v${vdate}_${BUILD_NUMBER}" port=22 target=root@xxx #srcdir="/mnt/deployment/mom-server/src" pwd=xxx cmd="sudo bash /mnt/scev6/b.sh restart && sudo bash /mnt/scev6/a.sh restart" ssh -p $port $target "$cmd" #ssh -p 22 -i xxx root@xxx echo 'end'