Skip to content

Commit e611b38

Browse files
authored
Merge pull request #5890 from tstromberg/cherry-7f5f4
CI: Retry GitHub status updates
2 parents c03aee8 + 5efde8b commit e611b38

File tree

2 files changed

+74
-11
lines changed

2 files changed

+74
-11
lines changed

hack/jenkins/common.sh

+38-6
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,43 @@ ${SUDO_PREFIX} rm -f "${KUBECONFIG}" || true
289289
rmdir "${TEST_HOME}"
290290
echo ">> ${TEST_HOME} completed at $(date)"
291291

292-
if [[ "${MINIKUBE_LOCATION}" != "master" ]]; then
293-
readonly target_url="https://storage.googleapis.com/minikube-builds/logs/${MINIKUBE_LOCATION}/${JOB_NAME}.txt"
294-
curl -s "https://api.github.com/repos/kubernetes/minikube/statuses/${COMMIT}?access_token=$access_token" \
295-
-H "Content-Type: application/json" \
296-
-X POST \
297-
-d "{\"state\": \"$status\", \"description\": \"Jenkins\", \"target_url\": \"$target_url\", \"context\": \"${JOB_NAME}\"}"
292+
if [[ "${MINIKUBE_LOCATION}" == "master" ]]; then
293+
exit $result
298294
fi
295+
296+
# retry_github_status provides reliable github status updates
297+
function retry_github_status() {
298+
local commit=$1
299+
local context=$2
300+
local state=$3
301+
local token=$4
302+
local target=$5
303+
304+
# Retry in case we hit our GitHub API quota or fail other ways.
305+
local attempt=0
306+
local timeout=2
307+
local code=-1
308+
309+
while [[ "${attempt}" -lt 8 ]]; do
310+
local out=$(mktemp)
311+
code=$(curl -o "${out}" -s --write-out "%{http_code}" -L \
312+
"https://api.github.com/repos/kubernetes/minikube/statuses/${commit}?access_token=${token}" \
313+
-H "Content-Type: application/json" \
314+
-X POST \
315+
-d "{\"state\": \"${state}\", \"description\": \"Jenkins\", \"target_url\": \"${target}\", \"context\": \"${context}\"}" || echo 999)
316+
317+
# 2xx HTTP codes
318+
if [[ "${code}" =~ ^2 ]]; then
319+
break
320+
fi
321+
322+
cat "${out}" && rm -f "${out}"
323+
echo "HTTP code ${code}! Retrying in ${timeout} .."
324+
sleep "${timeout}"
325+
attempt=$(( attempt + 1 ))
326+
timeout=$(( timeout * 2 ))
327+
done
328+
}
329+
330+
retry_github_status "${COMMIT}" "${JOB_NAME}" "${status}" "${access_token}" "https://storage.googleapis.com/minikube-builds/logs/${MINIKUBE_LOCATION}/${JOB_NAME}.txt"
299331
exit $result

hack/jenkins/minikube_set_pending.sh

+36-5
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,42 @@ jobs=(
4242
'none_Linux'
4343
)
4444

45+
# retry_github_status provides reliable github status updates
46+
function retry_github_status() {
47+
local commit=$1
48+
local context=$2
49+
local state=$3
50+
local token=$4
51+
local target=$5
52+
53+
# Retry in case we hit our GitHub API quota or fail other ways.
54+
local attempt=0
55+
local timeout=2
56+
local code=-1
57+
58+
while [[ "${attempt}" -lt 8 ]]; do
59+
local out=$(mktemp)
60+
code=$(curl -o "${out}" -s --write-out "%{http_code}" -L \
61+
"https://api.github.com/repos/kubernetes/minikube/statuses/${commit}?access_token=${token}" \
62+
-H "Content-Type: application/json" \
63+
-X POST \
64+
-d "{\"state\": \"${state}\", \"description\": \"Jenkins\", \"target_url\": \"${target}\", \"context\": \"${context}\"}" || echo 999)
65+
66+
# 2xx HTTP codes
67+
if [[ "${code}" =~ ^2 ]]; then
68+
break
69+
fi
70+
71+
cat "${out}" && rm -f "${out}"
72+
echo "HTTP code ${code}! Retrying in ${timeout} .."
73+
sleep "${timeout}"
74+
attempt=$(( attempt + 1 ))
75+
timeout=$(( timeout * 2 ))
76+
done
77+
}
78+
4579
for j in ${jobs[@]}; do
46-
target_url="https://storage.googleapis.com/minikube-builds/logs/${ghprbPullId}/${j}.txt"
47-
curl "https://api.github.com/repos/kubernetes/minikube/statuses/${ghprbActualCommit}?access_token=$access_token" \
48-
-H "Content-Type: application/json" \
49-
-X POST \
50-
-d "{\"state\": \"pending\", \"description\": \"Jenkins\", \"target_url\": \"${target_url}\", \"context\": \"${j}\"}"
80+
retry_github_status "${ghprbActualCommit}" "${j}" "pending" "${access_token}" \
81+
"https://storage.googleapis.com/minikube-builds/logs/${ghprbPullId}/${j}.txt"
5182
done
5283

0 commit comments

Comments
 (0)