Chore: Upgrade Jenkins-job-builder to 6.3.0
[releng/global-jjb.git] / shell / logs-deploy.sh
index 8756f72..d797fa7 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/bash -l
 # SPDX-License-Identifier: EPL-1.0
 ##############################################################################
 # Copyright (c) 2017 The Linux Foundation and others.
 ##############################################################################
 echo "---> logs-deploy.sh"
 
-# Ensure we fail the job if any steps fail.
-set -eu -o pipefail
+# shellcheck disable=SC1090
+source ~/lf-env.sh
+lf-activate-venv --python python3.8 lftools
 
-set -x  # Trace commands for this script to make debugging easier.
+# Ensure we fail the job if any steps fail
+# Disable 'globbing'
+set -euf -o pipefail
 
-ARCHIVE_ARTIFACTS="${ARCHIVE_ARTIFACTS:-}"
-LOGS_SERVER="${LOGS_SERVER:-None}"
+# The 'lftool deploy archives' command below expects the archives
+# directory to exist.  Normally lf-infra-sysstat or similar would
+# create it and add content, but to make sure this script is
+# self-contained, we ensure it exists here.
+mkdir -p "$WORKSPACE/archives"
 
-if [ "${LOGS_SERVER}" == 'None' ]
-then
-    set +x # Disable trace since we no longer need it
+get_pattern_opts () {
+    opts=()
+    for arg in ${ARCHIVE_ARTIFACTS:-}; do
+        opts+=("-p" "$arg")
+    done
+    echo "${opts[@]-}"
+}
 
-    echo "WARNING: Logging server not set"
+pattern_opts=$(get_pattern_opts)
+
+if [[ -z ${LOGS_SERVER:-} ]]; then
+    echo "WARNING: Nexus logging server not set"
 else
-    NEXUS_URL="${NEXUS_URL:-$NEXUSPROXY}"
-    NEXUS_PATH="${SILO}/${JENKINS_HOSTNAME}/${JOB_NAME}/${BUILD_NUMBER}"
-    BUILD_URL="${BUILD_URL}"
+    nexus_url="${NEXUSPROXY:-$NEXUS_URL}"
+    nexus_path="${SILO}/${JENKINS_HOSTNAME}/${JOB_NAME}/${BUILD_NUMBER}"
+    echo "INFO: Nexus URL $nexus_url path $nexus_path"
+
+    echo "INFO: archiving workspace using pattern(s): ${pattern_opts:-}"
+    # shellcheck disable=SC2086
+    lftools deploy archives ${pattern_opts:-} "$nexus_url" "$nexus_path" "$WORKSPACE"
+
+    echo "INFO: archiving logs to Nexus"
+    lftools deploy logs "$nexus_url" "$nexus_path" "${BUILD_URL:-}"
 
-    lftools deploy archives -p "$ARCHIVE_ARTIFACTS" "$NEXUS_URL" "$NEXUS_PATH" "$WORKSPACE"
-    lftools deploy logs "$NEXUS_URL" "$NEXUS_PATH" "$BUILD_URL"
+    echo "Nexus build logs: <a href=\"$LOGS_SERVER/$nexus_path\">$LOGS_SERVER/$nexus_path</a>"
+fi
+
+if [[ -z ${S3_BUCKET:-} ]]; then
+    echo "WARNING: S3 logging server not set"
+else
+    s3_path="logs/$SILO/$JENKINS_HOSTNAME/$JOB_NAME/$BUILD_NUMBER/"
+    echo "INFO: S3 path $s3_path"
 
-    set +x  # Disable trace since we no longer need it.
+    echo "INFO: archiving logs to S3"
+    # shellcheck disable=SC2086
+    lftools deploy s3 ${pattern_opts:-} "$S3_BUCKET" "$s3_path" \
+        "$BUILD_URL" "$WORKSPACE"
 
-    echo "Build logs: <a href=\"$LOGS_SERVER/$NEXUS_PATH\">$LOGS_SERVER/$NEXUS_PATH</a>"
+    echo "S3 build logs: <a href=\"https://$CDN_URL/$s3_path\">https://$CDN_URL/$s3_path</a>"
 fi