From: Thanh Ha Date: Thu, 15 Nov 2018 01:26:54 +0000 (+0800) Subject: Add error handling to stack script X-Git-Tag: v0.27.0~1^2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F44%2F13544%2F1;p=releng%2Fglobal-jjb.git Add error handling to stack script Handle case where JENKINS_URL does not return 200 ok. Change-Id: Ie2067c3a5f3f489e25c361a4f417a6325e4abbd1 Signed-off-by: Thanh Ha --- diff --git a/shell/openstack-cleanup-orphaned-stacks.sh b/shell/openstack-cleanup-orphaned-stacks.sh index 8f1851e1..8140adea 100644 --- a/shell/openstack-cleanup-orphaned-stacks.sh +++ b/shell/openstack-cleanup-orphaned-stacks.sh @@ -25,7 +25,13 @@ stack_in_jenkins() { JENKINS_URL="$jenkins/computer/api/json?tree=computer[executors[currentExecutable[url]],oneOffExecutors[currentExecutable[url]]]&xpath=//url&wrapper=builds" resp=$(curl -s -w "\\n\\n%{http_code}" --globoff -H "Content-Type:application/json" "$JENKINS_URL") json_data=$(echo "$resp" | head -n1) - #status=$(echo "$resp" | awk 'END {print $NF}') + status=$(echo "$resp" | awk 'END {print $NF}') + + if [ "$status" != 200 ]; then + >&2 echo "ERROR: Failed to fetch data from $JENKINS_URL with status code $status" + >&2 echo "$resp" + exit 1 + fi if [[ "${jenkins}" == *"jenkins."*".org" ]] || [[ "${jenkins}" == *"jenkins."*".io" ]]; then silo="production"