jjb: infra: bifrost-upload-logs.sh: Copy landing page to the GS server
[releng.git] / jjb / infra / bifrost-upload-logs.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 SUSE.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 set -eu
12 set -o pipefail
13
14 BIFROST_CONSOLE_LOG="${BUILD_URL}/consoleText"
15 BIFROST_GS_URL=${BIFROST_LOG_URL/http:/gs:}
16 BIFROST_COMPRESS_SUFFIX="tar.gz"
17 BIFROST_COMPRESSED_LOGS=()
18
19 echo "Uploading build logs to ${BIFROST_LOG_URL}"
20
21 echo "Uploading console output"
22 curl -L ${BIFROST_CONSOLE_LOG} | gsutil cp - ${BIFROST_GS_URL}/build_log.txt
23
24 [[ ! -d ${WORKSPACE}/logs ]] && exit 0
25
26 pushd ${WORKSPACE}/logs/ &> /dev/null
27 for x in *.log; do
28     echo "Compressing and uploading $x"
29     tar -czf - $x | gsutil cp - ${BIFROST_GS_URL}/${x}.${BIFROST_COMPRESS_SUFFIX} 1>/dev/null
30     BIFROST_COMPRESSED_LOGS+=(${x}.${BIFROST_COMPRESS_SUFFIX})
31 done
32 popd &> /dev/null
33
34 echo "Generating the landing page"
35 cat > index.html << EOF
36 <html>
37 <h1>Build results for <a href=https://$GERRIT_NAME/#/c/$GERRIT_CHANGE_NUMBER>$GERRIT_NAME/$GERRIT_CHANGE_NUMBER</a></h1>
38 <h2>Job: $JOB_NAME</h2>
39 <ul>
40 <li><a href=${BIFROST_LOG_URL}/build_log.txt>build_log.txt</a></li>
41 EOF
42
43 for x in ${BIFROST_COMPRESSED_LOGS[@]}; do
44     echo "<li><a href=${BIFROST_LOG_URL}/${x}>${x}</a></li>" >> index.html
45 done
46
47 cat >> index.html << EOF
48 </ul>
49 </html>
50 EOF
51
52 gsutil cp index.html ${BIFROST_GS_URL}/index.html