Chore: Upgrade Jenkins-job-builder to 6.3.0
[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 # shellcheck disable=SC1090
14 source ~/lf-env.sh
15 lf-activate-venv --python python3.8 lftools
16
17 # Ensure we fail the job if any steps fail
18 # Disable 'globbing'
19 set -euf -o pipefail
20
21 # The 'lftool deploy archives' command below expects the archives
22 # directory to exist.  Normally lf-infra-sysstat or similar would
23 # create it and add content, but to make sure this script is
24 # self-contained, we ensure it exists here.
25 mkdir -p "$WORKSPACE/archives"
26
27 get_pattern_opts () {
28     opts=()
29     for arg in ${ARCHIVE_ARTIFACTS:-}; do
30         opts+=("-p" "$arg")
31     done
32     echo "${opts[@]-}"
33 }
34
35 pattern_opts=$(get_pattern_opts)
36
37 if [[ -z ${LOGS_SERVER:-} ]]; then
38     echo "WARNING: Nexus logging server not set"
39 else
40     nexus_url="${NEXUSPROXY:-$NEXUS_URL}"
41     nexus_path="${SILO}/${JENKINS_HOSTNAME}/${JOB_NAME}/${BUILD_NUMBER}"
42     echo "INFO: Nexus URL $nexus_url path $nexus_path"
43
44     echo "INFO: archiving workspace using pattern(s): ${pattern_opts:-}"
45     # shellcheck disable=SC2086
46     lftools deploy archives ${pattern_opts:-} "$nexus_url" "$nexus_path" "$WORKSPACE"
47
48     echo "INFO: archiving logs to Nexus"
49     lftools deploy logs "$nexus_url" "$nexus_path" "${BUILD_URL:-}"
50
51     echo "Nexus build logs: <a href=\"$LOGS_SERVER/$nexus_path\">$LOGS_SERVER/$nexus_path</a>"
52 fi
53
54 if [[ -z ${S3_BUCKET:-} ]]; then
55     echo "WARNING: S3 logging server not set"
56 else
57     s3_path="logs/$SILO/$JENKINS_HOSTNAME/$JOB_NAME/$BUILD_NUMBER/"
58     echo "INFO: S3 path $s3_path"
59
60     echo "INFO: archiving logs to S3"
61     # shellcheck disable=SC2086
62     lftools deploy s3 ${pattern_opts:-} "$S3_BUCKET" "$s3_path" \
63         "$BUILD_URL" "$WORKSPACE"
64
65     echo "S3 build logs: <a href=\"https://$CDN_URL/$s3_path\">https://$CDN_URL/$s3_path</a>"
66 fi