728x90
반응형
linux command로 script를 (특히 jenkins 배치잡으로) 실행할 때 배치잡이 실패하는 경우 횟수 조건을 줘서 retry 하도록 하는 command를 알아본다.
#!/bin/bash
slack_webhook_url = <slack_webhook_url>
retry_limit=3
# seconds
timegap=60
<script command>
job_step_result=$?
echo "job_step_result: $job_step_result"
if [[ $job_step_result -ne 0 ]]; then
for i in $(seq 1 $retry_limit); do
echo "retry $i time, waiting $timegap sec..."
# message to slack
message="retry $i time, waiting $timegap sec... job $JOB_NAME, $JOB_DISPLAY_URL"
curl -X POST --data-urlencode "payload={\"channel\": \"#noti-channel\", \"username\": \"user_name\", \"text\": \"$message\", \"icon_emoji\": \":large_orange_circle:\"}" $slack_webhook_url
# wait
sleep $timegap
<script command>
job_step_result=$?
if [[ $job_step_result -eq 0 ]]; then
break
fi
done
fi
job_result=$job_step_result
echo "job_result code: $job_result"
if [[ $job_result -ne 0 ]]; then
message="error job $JOB_NAME, $JOB_DISPLAY_URL"
curl -X POST --data-urlencode "payload={\"channel\": \"#noti-channel\", \"username\": \"user_name\", \"text\": \"$message\", \"icon_emoji\": \":red_circle:\"}" $slack_webhook_url
echo "error!"
exit $job_result
fi
Reference
반응형
'[OS]Operating System > [Linux]' 카테고리의 다른 글
[Linux] Linux Partition (0) | 2024.03.09 |
---|---|
[Linux] 파일 이동 및 이름 바꾸기 (3) | 2024.03.05 |
[Linux] bash shell - 조건문 사용법 (0) | 2023.06.13 |
[Linux] shell code - [], [[]], (), (()) 차이 (0) | 2023.04.30 |
[Linux] shell script - python exit code (0) | 2023.04.30 |