思路:
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