Fix update to logs-deploy.sh
[releng/global-jjb.git] / shell / logs-deploy.sh
1 #!/bin/bash -l
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 echo "---> logs-deploy.sh"
12
13 # Ensure we fail the job if any steps fail
14 # Disable 'globbing'
15 set -euf -o pipefail
16
17 function get_pattern_opts()
18 {
19     opts=()
20     for arg in ${ARCHIVE_ARTIFACTS:-}; do
21         opts+=("-p" "$arg")
22     done
23     echo "${opts[@]-}"
24 }
25
26 pattern_opts=$(get_pattern_opts)
27
28 if [[ -z ${LOGS_SERVER:-} ]]; then
29     echo "WARNING: Nexus logging server not set"
30 else
31     nexus_url="${NEXUSPROXY:-$NEXUS_URL}"
32     nexus_path="${SILO}/${JENKINS_HOSTNAME}/${JOB_NAME}/${BUILD_NUMBER}"
33     echo "INFO: Nexus URL $nexus_url path $nexus_path"
34
35     echo "INFO: archiving workspace using pattern(s): ${pattern_opts:-}"
36     # shellcheck disable=SC2086
37     lftools deploy archives ${pattern_opts:-} "$nexus_url" "$nexus_path" "$WORKSPACE"
38
39     echo "INFO: archiving logs to Nexus"
40     lftools deploy logs "$nexus_url" "$nexus_path" "${BUILD_URL:-}"
41
42     echo "Nexus build logs: <a href=\"$LOGS_SERVER/$nexus_path\">$LOGS_SERVER/$nexus_path</a>"
43 fi
44
45 if [[ -z ${S3_BUCKET:-} ]]; then
46     echo "WARNING: S3 logging server not set"
47 else
48     s3_path="$SILO/$JENKINS_HOSTNAME/$JOB_NAME/$BUILD_NUMBER/"
49     echo "INFO: S3 path $s3_path"
50
51     echo "INFO: archiving logs to S3"
52     # shellcheck disable=SC2086
53     lftools deploy s3 ${pattern_opts:-} "$S3_BUCKET" "$s3_path" \
54         "$BUILD_URL" "$WORKSPACE"
55
56     echo "S3 build logs: <a href=\"https://$CDN_URL/$s3_path\"></a>"
57 fi
58