[Jenkins] 新的檢查工作迴圈-確保執行 job build 執行完成後 接續執行
[Jenkins] 新的檢查工作迴圈-確保執行 job build 執行完成後 接續執行
#!/bin/bash
#$CN_TT_IN_StatusCheck
Jname=`echo $JOB_NAME | tr [:upper:] [:lower:] | cut -c1-2`
echo $Jname
timedir=$(date +%F)
echo $timedir
/usr/bin/mkdir -p /home/F5/jenkins_log/$Jname-$timedir
jbnamevab=$TH_KU_HK_PoolMember_Status_Check5_vab
#
#
for i in $(echo $jbnamevab | sed "s/,/\n/g" );
do
echo $i
curl -X POST http://127.0.0.1:8080/jenkins/job/$i/build?delay=0sec --user $USERNAME:$PASSWORD
sleep 5
done
echo Build finished
/usr/bin/touch /home/F5/jenkins_log/$JOB_NAME-$BUILD_NUMBER-log-file
#
for i in $(echo $jbnamevab | sed "s/,/\n/g" );
do
JOB_URL=http://127.0.0.1:8080/jenkins/job/$i
JOB_STATUS_URL=${JOB_URL}/lastBuild/api/json
GREP_RETURN_CODE=0
# Start the build
#curl --user "$USERNAME:$PASSWORD" $JOB_URL/build?delay=0sec
# Poll every 10 second until the build is finished
while [ $GREP_RETURN_CODE -eq 0 ]
do
sleep 3
# Grep will return 0 while the build is running:
curl --user "$USERNAME:$PASSWORD" $JOB_STATUS_URL | grep result\":null > /dev/null
GREP_RETURN_CODE=$?
done
echo "Build Check finished"
echo -e "$i" | cat >> /home/F5/jenkins_log/$JOB_NAME-$BUILD_NUMBER-log-file
/usr/bin/find /home/F5/jenkins_log/$i-* -type f -amin -10 -exec cat {} \;| grep "offline\|disabled" | awk '{ print $1 " " $4 " 連線數: " $9 }' >> /home/F5/jenkins_log/$JOB_NAME-$BUILD_NUMBER-log-file
echo "$i-Out-put-log"
#
mv /home/F5/jenkins_log/$i-* /home/F5/jenkins_log/$Jname-$timedir
sleep 5
done
#
#
# 顯示執行清單
sleep 10
# 請設定 60 分秒後在撈取執行清單
#
Sname=`echo $JOB_NAME | tr [:upper:] [:lower:] | cut -c1-2`
#cat /home/F5/jenkins_log/$JOB_NAME-$BUILD_NUMBER-log-file | /home/F5/slackweb.sh $JOB_NAME-$BUILD_NUMBER
cat /home/F5/jenkins_log/$JOB_NAME-$BUILD_NUMBER-log-file | /home/F5/slackweb_Test.sh $JOB_NAME-$BUILD_NUMBER $Sname
#
for i in $(echo $jbnamevab | sed "s/,/\n/g" );
do
echo $i
curl -s http://127.0.0.1:8080/jenkins/job/$i/lastBuild/consoleText --user $USERNAME:$PASSWORD
sleep 2
done
mv /home/F5/jenkins_log/$JOB_NAME-* /home/F5/jenkins_log/$Jname-$timedir
Jenkins job build config.xml
沒有留言:
張貼留言