Jenkins添加健康检查
# 1. chkhealth函数
在每个JOB的command位置增加,在monitor 上面增加函数
chkhealth() {
#根据每个工程的启动时间修改
sleep 30s
#如果端口不是eth0请修改
ip=$(/sbin/ifconfig eth0|grep inet|head -n 1|awk '{print $2}')
修改为每个工程的端口
port="8080"
http_code=`curl -m 3 -o /dev/null -s -w %{http_code} "http://$ip:$port"`
if [ "${http_code}" -eq "200" ];then
echo "check $ip sucess status is ${http_code}"
elif [ "${http_code}" -eq "301" ];then
echo "check $ip sucess status is ${http_code}"
elif [ "${http_code}" -eq "302" ];then
echo "check $ip sucess status is ${http_code}"
elif [ "${http_code}" -eq "401" ];then
echo "check $ip sucess status is ${http_code}"
elif [ "${http_code}" -eq "403" ];then
echo "check $ip sucess status is ${http_code}"
elif [ "${http_code}" -eq "404" ];then
echo "check $ip sucess status is ${http_code}"
elif [ "${http_code}" -eq "405" ];then
echo "check $ip sucess status is ${http_code}"
else
echo "check $ip fail status is ${http_code}"
fi
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 2. 添加函数
在主函数 function monitor() 最下面增加
chkhealth
# 3. 修改变量
sleep 的时间 根据每个工程的启动时间修改
ip 如果端口不是eth0请修改
port 修改为每个工程的端口
上次更新: 2022/09/30, 15:27:27