upload_to_nexus to return a non-zero exit status 22/8622/2
authorRobert Varga <nite@hq.sk>
Wed, 31 Jan 2018 11:03:28 +0000 (12:03 +0100)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Wed, 31 Jan 2018 21:25:25 +0000 (16:25 -0500)
As it turns out Nexus does not produce a http status code on upload
failure and returns back a blank message. This means if we do not
detect a successful status from Nexus we need to exit 1 explicity
to make sure we return to parallel a proper error status code.

JIRA: RELENG-765
Change-Id: Ic221c668bb6cd35befc614159ee8d7220d3f4cfe
Co-authored-by: Thanh Ha <thanh.ha@linuxfoundation.org>
Signed-off-by: Robert Varga <nite@hq.sk>
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
shell/deploy

index c664c36..b72ae07 100755 (executable)
@@ -712,13 +712,14 @@ upload_to_nexus() {
     echo "Uploading ${file}"
 
     local resp
-    resp=$(curl -s -w "%{http_code}" --netrc --upload-file "$file" "$nexus_repo_url/$file")
+    resp=$(curl -s -w "\\n\\n%{http_code}" --netrc --upload-file "$file" "$nexus_repo_url/$file")
+    data=$(echo "$resp" | head -n1)
     status=$(echo "$resp" | awk 'END {print $NF}')
 
     if [ "$status" != "201" ]; then
-        echo "ERROR: Failed to upload to Nexus. Aborting..."
-        echo "$resp"
-        exit "$status"
+        echo "ERROR: Failed to upload to Nexus with status code $status. Aborting..."
+        echo "HTTP Response: $data"
+        exit 1
     fi
 }