Add more attempts to submits Coverity Scan results 63/92463/1
authorArtem Naluzhnyy <A.Naluzhnyy@samsung.com>
Thu, 1 Aug 2019 12:38:18 +0000 (14:38 +0200)
committerArtem Naluzhnyy <A.Naluzhnyy@samsung.com>
Thu, 1 Aug 2019 12:38:18 +0000 (14:38 +0200)
Since the build process takes a lot of time and resources on our Jenkins
executors it had better try to resubmit our results to Coverity Scan
server if it replies with non-200 HTTP response.

Issue-ID: CIMAN-260
Signed-off-by: Artem Naluzhnyy <A.Naluzhnyy@samsung.com>
Change-Id: I8fd24d9f4f6181ff6e0817914ac649a140706b7e

shell/maven-coverity.sh

index 22a42c2..f263963 100644 (file)
@@ -19,6 +19,9 @@ PS4='+['$(readlink -f "$0")' ${FUNCNAME[0]%main}#$LINENO] '
 
 echo '---> maven-coverity.sh'
 
+SUBMISSION_ATTEMPTS=5
+SUBMISSION_INITIAL_REST_INTERVAL=30 # seconds, will be doubled after each attempt
+
 #-----------------------------------------------------------------------------
 # Process parameters for JS/PHP/Ruby files analysis
 
@@ -148,18 +151,36 @@ tar \
   --file='results.tgz' \
   'cov-int'
 
-curl \
-  --verbose \
-  --silent \
-  --show-error \
-  --fail \
-  --form "project=${COVERITY_PROJECT_NAME}" \
-  --form "email=${COVERITY_USER_EMAIL}" \
-  --form "token=${COVERITY_TOKEN}" \
-  --form 'file=@results.tgz' \
-  --form "version=${GIT_COMMIT:0:7}" \
-  --form "description=${GIT_BRANCH}" \
-  'https://scan.coverity.com/builds'
+for (( ATTEMPT=1; ATTEMPT<=SUBMISSION_ATTEMPTS; ATTEMPT++ )); do
+  CURL_OUTPUT=$(
+    curl \
+      --verbose \
+      --silent \
+      --show-error \
+      --fail \
+      --write-out '\n%{http_code}' \
+      --form "project=${COVERITY_PROJECT_NAME}" \
+      --form "email=${COVERITY_USER_EMAIL}" \
+      --form "token=${COVERITY_TOKEN}" \
+      --form 'file=@results.tgz' \
+      --form "version=${GIT_COMMIT:0:7}" \
+      --form "description=${GIT_BRANCH}" \
+      'https://scan.coverity.com/builds'
+  )
+  HTTP_RESPONSE_CODE=$(echo -n "${CURL_OUTPUT}" | tail -1)
+  test x"${HTTP_RESPONSE_CODE}" = x"200" \
+    && break
+
+  sleep "${SUBMISSION_REST_INTERVAL:-$SUBMISSION_INITIAL_REST_INTERVAL}"
+
+  SUBMISSION_REST_INTERVAL=$(( ${SUBMISSION_REST_INTERVAL:-$SUBMISSION_INITIAL_REST_INTERVAL} * 2 ))
+done
+
+HTTP_RESPONSE=$(echo -n "${CURL_OUTPUT}" | head -n -1 | tr -d '\n')
+if [ x"${HTTP_RESPONSE}" != x"Build successfully submitted." ]; then
+  echo "Coverity Scan service responded with '${HTTP_RESPONSE}' while 'Build successfully submitted.' expected." >&2
+  exit 1
+fi
 
 #-----------------------------------------------------------------------------