Jenkins 结合shell检查某个页面是否加载成功。

 

思路:

1. 先有一个Jenkins Job 生成一个测试报告,测试报告可以分析本期请求成功率。

2. 第二个Job根据第一个Job的报告,由Shell 完成分析,决定是否触发报告,请求不是100%成功,即触发报警邮件。

#!/bin/sh

#cp /opt/jenkins-slave/workspace/workspace/Monitor-Uniqlo-Official-Web/Monitor_web_loading/TestReport/html/Monitor-Uniqlo-Official-Web-201808231407.html .

rm Monitor_web_loading/TestReport/html/*
cp /opt/jenkins-slave/workspace/workspace/Monitor-Uniqlo-Official-Web/TestReport/html/Monitor-Uniqlo-Official-Web*.html Monitor_web_loading/TestReport/html/

a=$(sed -n '53p' /opt/jenkins-slave/workspace/workspace/Monitor-Uniqlo-Official-Web/TestReport/html/Monitor-Uniqlo-Official-Web*.html | grep '100.00%')
echo $a

if [ "$a" = "" ]
then
     echo "Uniqlo web is not loaded completely, Please check with administrator!"
     exit 1
else
     echo "Uniqlo web is loaded without any problem"

fi

除了有sed处理字符串,也可以用awk处理字符串。

​
#!/bin/sh

#cp /opt/jenkins-slave/workspace/workspace/Monitor-Uniqlo-Official-Web/Monitor_web_loading/TestReport/html/Monitor-Uniqlo-Official-Web-201808231407.html .

rm Monitor_web_loading/TestReport/html/*
cp /opt/jenkins-slave/workspace/workspace/Monitor-Uniqlo-Official-Web/TestReport/html/Monitor-Uniqlo-Official-Web*.html Monitor_web_loading/TestReport/html/

#a=$(sed -n '142p' /opt/jenkins-slave/workspace/workspace/Monitor-Uniqlo-Official-Web/TestReport/html/Monitor-Uniqlo-Official-Web*.html | grep '100.00%')
a=$(cat /opt/jenkins-slave/workspace/workspace/Monitor-Uniqlo-Official-Web/TestReport/html/Monitor-Uniqlo-Official-Web*.html |awk -F'<td align="center">' '{print $5}'|awk -F'<' '{print $1}')
echo $a

if [ "$a" != "100.00%" ]
then
     echo "Uniqlo web is not loaded completely, Please check with administrator!"
     exit 1
else
     echo "Uniqlo web is loaded without any problem"

fi

​

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值