Skip to content

Commit e0ff942

Browse files
authored
Adding a retry logic when the API call was failed on Gradle-check (#4305)
Signed-off-by: Jeff Lu <chunglu@amazon.com>
1 parent 19e09ca commit e0ff942

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

scripts/gradle/gradle-check.sh

100644100755
+32-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,36 @@ TRIGGER_TOKEN=$1
2020
PR_TITLE_NEW=`echo $pr_title | tr -dc '[:alnum:] ' | tr '[:upper:]' '[:lower:]'`
2121
PAYLOAD_JSON="{\"pr_from_sha\": \"$pr_from_sha\", \"pr_from_clone_url\": \"$pr_from_clone_url\", \"pr_to_clone_url\": \"$pr_to_clone_url\", \"pr_title\": \"$PR_TITLE_NEW\", \"pr_number\": \"$pr_number\"}"
2222

23+
perform_curl_and_process_with_jq() {
24+
local url=$1
25+
local jq_filter=$2
26+
local max_retries=$3
27+
local count=0
28+
local success=false
29+
30+
while [ "$count" -lt "$max_retries" ]; do
31+
response=$(curl -s -XGET "${url}api/json")
32+
processed_response=$(echo "$response" | jq --raw-output "$jq_filter")
33+
jq_exit_code=$?
34+
35+
if [ "$jq_exit_code" -eq "0" ]; then
36+
success=true
37+
echo "$processed_response"
38+
break
39+
else
40+
echo "Attempt $((count+1))/$max_retries failed. The jq processing failed with exit code: $jq_exit_code. Retrying..."
41+
fi
42+
43+
count=$((count+1))
44+
sleep 5
45+
done
46+
47+
if [ "$success" != "true" ]; then
48+
echo "Failed to retrieve and process data after $max_retries attempts."
49+
exit 1
50+
fi
51+
}
52+
2353
echo "Trigger Jenkins workflows"
2454
JENKINS_REQ=`curl -s -XPOST \
2555
-H "Authorization: Bearer $TRIGGER_TOKEN" \
@@ -50,7 +80,8 @@ if [ -z "$QUEUE_URL" ] || [ "$QUEUE_URL" != "null" ]; then
5080
echo "Jenkins Workflow Url: $WORKFLOW_URL"
5181
TIMEPASS=$(( TIMEPASS + 30 )) && echo time pass: $TIMEPASS
5282
sleep 30
53-
RUNNING=$(curl -s -XGET ${WORKFLOW_URL}api/json | jq --raw-output .building)
83+
RUNNING=$(perform_curl_and_process_with_jq "$WORKFLOW_URL" ".building" 5)
84+
echo "Workflow running status :$RUNNING"
5485
done
5586

5687
if [ "$RUNNING" = "true" ]; then

0 commit comments

Comments
 (0)