From ec81f73b2241a9ceeccf6f09bf9de5a09f178a16 Mon Sep 17 00:00:00 2001 From: Artem Naluzhnyy Date: Thu, 1 Aug 2019 14:38:18 +0200 Subject: Add more attempts to submits Coverity Scan results 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 Change-Id: I8fd24d9f4f6181ff6e0817914ac649a140706b7e --- shell/maven-coverity.sh | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/shell/maven-coverity.sh b/shell/maven-coverity.sh index 22a42c2d5..f263963fe 100644 --- a/shell/maven-coverity.sh +++ b/shell/maven-coverity.sh @@ -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 #----------------------------------------------------------------------------- -- cgit 1.2.3-korg