Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a retry logic when the API call was failed on Gradle-check #4295

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion scripts/gradle/gradle-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ RESULT="null"
TRIGGER_TOKEN=$1
PR_TITLE_NEW=`echo $pr_title | tr -dc '[:alnum:] ' | tr '[:upper:]' '[:lower:]'`
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\"}"
MAX_API_RETRY_COUNT=2

echo "Trigger Jenkins workflows"
JENKINS_REQ=`curl -s -XPOST \
Expand All @@ -43,14 +44,31 @@ if [ -z "$QUEUE_URL" ] || [ "$QUEUE_URL" != "null" ]; then
if [ -z "$WORKFLOW_URL" ] || [ "$WORKFLOW_URL" != "null" ]; then

RUNNING="true"
RETRY_COUNT=0

echo "Waiting for Jenkins to complete the run"
while [ "$RUNNING" = "true" ] && [ "$TIMEPASS" -le "$TIMEOUT" ]; do
echo "Still running, wait for another 30 seconds before checking again, max timeout $TIMEOUT"
echo "Jenkins Workflow Url: $WORKFLOW_URL"
TIMEPASS=$(( TIMEPASS + 30 )) && echo time pass: $TIMEPASS
sleep 30
RUNNING=$(curl -s -XGET ${WORKFLOW_URL}api/json | jq --raw-output .building)

CURL_RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" -XGET "${WORKFLOW_URL}api/json")
while [ "$CURL_RESPONSE_CODE" != "200" ] && [ "$RETRY_COUNT" -le "$MAX_API_RETRY_COUNT" ]; do
echo "API call failed with HTTP code: $CURL_RESPONSE_CODE. Retrying in 5 seconds..."
sleep 5
RETRY_COUNT=$((RETRY_COUNT + 1))
CURL_RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" -XGET "${WORKFLOW_URL}api/json")
done

if [ "$CURL_RESPONSE_CODE" = "200" ]; then
RUNNING=$(curl -s -XGET "${WORKFLOW_URL}api/json" | jq --raw-output .building)
fi

if [ "$RETRY_COUNT" -ge "$MAX_API_RETRY_COUNT" ]; then
echo "API failed after $MAX_API_RETRY_COUNT attempts. Exiting script."
exit 1
fi
done

if [ "$RUNNING" = "true" ]; then
Expand Down
Loading