当前位置:网站首页>【shell】jenkins shell实现自动部署
【shell】jenkins shell实现自动部署
2022-06-29 13:49:00 【bulabula2022】
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
[email protected]
#pwd="cobbler"
pwd=/home/devops/.ssh/id_rsa
cmd="sudo rsync -avP -e \"ssh -i /root/.ssh/id_rsa\" /mnt/scev6/war/ [email protected]:/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 [email protected]
echo '传输文件到腾讯云服务器(124.223.62.51)上完成......'3.启动服务
#!/bin/bash vdate=`date +'%Y%m%d%H%M%S'` tg="v${vdate}_${BUILD_NUMBER}" port=22 [email protected] #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 [email protected] echo 'end'
边栏推荐
猜你喜欢

leetcode:226. 翻转二叉树

疯狂的数字藏品,下一个造富神话?

中康控股开启招股:拟募资净额3.95亿港元,预计7月12日上市

leetcode:226. Flip binary tree

TikTok全球短视频霸主地位或被YouTube反超

VQA不只需要图片,还需要外部知识!华盛顿大学&微软提出提出REVIVE,用GPT-3和Wikidata来辅助回答问题!...

揭秘百度智能测试在测试自动执行领域实践

Introduction to reverse commissioning -pe file section table and block 03/07

微信小程序:装B神器P图修改微信流量主小程序源码下载趣味恶搞图制作免服务器域名

Uncover the practice of Baidu intelligent test in the field of automatic test execution
随机推荐
golang6 反射
Open source machine learning platform
Shell——文本处理命令
吐血整理:一份不可多得的架构师图谱!
纳人才,谋发展 | 人大金仓喜获“最佳雇主校招案例奖”
go-zero微服务实战系列(七、请求量这么高该如何优化)
Hardware development notes (VIII): basic process of hardware development, making a USB to RS232 module (VII): creating a basic dip component (crystal oscillator) package and associating the principle
微信小程序:装B神器P图修改微信流量主小程序源码下载趣味恶搞图制作免服务器域名
goby全端口扫描
Redis的五种数据结构的底层实现原理
HTAP X 云原生: TiDB 加速释放数据价值,实现数据敏捷
STM32 watchdog study
【VEUX开发者工具的使用-getters使用】
Redis的持久化机制
VQA不只需要图片,还需要外部知识!华盛顿大学&微软提出提出REVIVE,用GPT-3和Wikidata来辅助回答问题!...
【烹饪记录】--- 酸辣白菜
Redis fragment cluster setup and use tutorial
Detailed explanation of machine learning out of fold prediction | using out of fold prediction oof to evaluate the generalization performance of models and build integrated models
【黑马早报】中公教育市值蒸发逾2000亿;新东方直播粉丝破2000万;HM关闭中国首店;万科郁亮称房地产已触底;微信上线“大爆炸”功能...
Goby full port scan