Handle missing CREDENTIAL when creating .netrc 83/11083/1
authorThanh Ha <thanh.ha@linuxfoundation.org>
Wed, 6 Jun 2018 20:57:55 +0000 (16:57 -0400)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Wed, 6 Jun 2018 21:08:16 +0000 (17:08 -0400)
Move the `set -eu -o pipefail` to after CREDENTIAL is set so that
we can properly error handle. Otherwise the script will exit too
soon.

Change-Id: I58edd3deb5b928a9ebaa4e00f6ed83d652e62d70
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
shell/create-netrc.sh

index 50a419c..a123be8 100644 (file)
 ##############################################################################
 echo "---> create-netrc.sh"
 
-# Ensure we fail the job if any steps fail.
-set -eu -o pipefail
-
-ALT_NEXUS_URL="${ALT_NEXUS_URL:-}"
-
-if [ -z "$ALT_NEXUS_URL" ]
-then
+if [ -z "$ALT_NEXUS_URL" ]; then
     NEXUS_URL="${NEXUSPROXY:-$NEXUS_URL}"
 else
     NEXUS_URL="${ALT_NEXUS_URL}"
 fi
-
 CREDENTIAL=$(xmlstarlet sel -N "x=http://maven.apache.org/SETTINGS/1.0.0" \
     -t -m "/x:settings/x:servers/x:server[x:id='${SERVER_ID}']" \
     -v x:username -o ":" -v x:password \
     "$SETTINGS_FILE")
 
+# Ensure we fail the job if any steps fail.
+set -eu -o pipefail
+
+# Handle when a project chooses to not archive logs to a log server
+# in other cases if CREDENTIAL is not found then fail the build.
+if [ -z "$CREDENTIAL" ] && [ "$SERVER_ID" == "logs" ]; then
+    echo "WARN: Log server credential not found."
+    exit 0
+elif [ -z "$CREDENTIAL" ]; then
+    echo "ERROR: Credential not found."
+    exit 1
+fi
+
 machine=$(echo "$NEXUS_URL" | awk -F/ '{print $3}')
 user=$(echo "$CREDENTIAL" | cut -f1 -d:)
 pass=$(echo "$CREDENTIAL" | cut -f2 -d:)