Skip to content

Commit

Permalink
Merge pull request #34 from rekhamitt/master
Browse files Browse the repository at this point in the history
Error handling for the sonar task status

Fixes #33
  • Loading branch information
headcr4sh authored Jan 25, 2019
2 parents d7da40e + 7c57f35 commit 47a2cd3
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions assets/in
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,27 @@ fi
cd "${dest}"
ce_task_info="./ce_task.json"
ce_error="./ce_error"
ce_task_status="PENDING"
until [ "${ce_task_status}" != "PENDING" ] && [ "${ce_task_status}" != "IN_PROGRESS" ]; do
sq_ce_task "${sonar_token}" "${sonar_host_url}" "${ce_task_id}" > "${ce_task_info}"
ce_task_error=""
attempt=0
max_attempts=2
until [ "${ce_task_status}" != "PENDING" ] && [ "${ce_task_status}" != "IN_PROGRESS" ] && [ -n "${ce_task_status}" ]; do
attempt=$(( attempt + 1 ))
set +e
sq_ce_task "${sonar_token}" "${sonar_host_url}" "${ce_task_id}" > "${ce_task_info}" 2>"${ce_error}" || { ce_task_error=$(<"${ce_error}"); }
set -e
ce_task_status=$(jq -r '.task.status // ""' < "${ce_task_info}")
if [[ $attempt -gt $max_attempts ]] && [[ -z "${ce_task_status}" ]] ; then
jq -n "{
version: { ce_task_id: \"${ce_task_id}\"},
metadata: [
{ name: \"ce_task_status\", value: \"error: ${ce_task_error}\" }
]
}" >&3
exit 1
fi
if [[ "${ce_task_status}" != "PENDING" ]] && [[ "${ce_task_status}" != "IN_PROGRESS" ]]; then
echo "Waiting for compute engine result (sleep: 5s)..."
sleep 5 # Poll SonarQube compute engine task every 5 seconds.
Expand All @@ -80,4 +97,4 @@ jq -n "{
{ name: \"ce_task_status\", value: \"${ce_task_status}\" },
{ name: \"project_status\", value: \"${project_status}\" }
]
}" >&3
}" >&3

0 comments on commit 47a2cd3

Please sign in to comment.