Merge "Bottlenecks: run env preparation inside the container"
[releng.git] / jjb / armband / upload-artifacts.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Ericsson AB and others.
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 set -o pipefail
11
12 # check if we built something
13 if [ -f $WORKSPACE/.noupload ]; then
14     echo "Nothing new to upload. Exiting."
15     /bin/rm -f $WORKSPACE/.noupload
16     exit 0
17 fi
18
19 # source the opnfv.properties to get ARTIFACT_VERSION
20 source $WORKSPACE/opnfv.properties
21
22 # storing ISOs for verify & merge jobs will be done once we get the disk array
23 if [[ ! "$JOB_NAME" =~ (verify|merge) ]]; then
24     # store ISO locally on NFS first
25     ISOSTORE="/home/jenkins/opnfv/iso_store"
26     if [[ -d "$ISOSTORE" ]]; then
27         # remove all but most recent 3 ISOs first to keep iso_mount clean & tidy
28         cd $ISOSTORE
29         ls -tp | grep -v '/' | tail -n +4 | xargs -d '\n' /bin/rm -f --
30
31         # store ISO
32         echo "Storing latest ISO in local storage"
33         touch .storing
34         /bin/cp -f $BUILD_DIRECTORY/opnfv-$OPNFV_ARTIFACT_VERSION.iso \
35             $ISOSTORE/opnfv-$OPNFV_ARTIFACT_VERSION.iso
36         rm .storing
37     fi
38 fi
39
40 # log info to console
41 echo "Uploading armband artifacts. This could take some time..."
42 echo
43
44 echo "Started at $(date)"
45 cd $WORKSPACE
46 # upload artifact and additional files to google storage
47 gsutil cp $BUILD_DIRECTORY/opnfv-$OPNFV_ARTIFACT_VERSION.iso \
48     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso > gsutil.iso.log 2>&1
49 gsutil cp $WORKSPACE/opnfv.properties \
50     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.properties > gsutil.properties.log 2>&1
51 if [[ ! "$JOB_NAME" =~ (verify|merge) ]]; then
52     gsutil cp $WORKSPACE/opnfv.properties \
53     gs://$GS_URL/latest.properties > gsutil.latest.log 2>&1
54 elif [[ "$JOB_NAME" =~ "merge" ]]; then
55     echo "Uploaded Armband Fuel ISO for a merged change"
56 fi
57 echo "Ended at $(date)"
58
59 gsutil -m setmeta \
60     -h "Content-Type:text/html" \
61     -h "Cache-Control:private, max-age=0, no-transform" \
62     gs://$GS_URL/latest.properties \
63     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.properties > /dev/null 2>&1
64
65 gsutil -m setmeta \
66     -h "Cache-Control:private, max-age=0, no-transform" \
67     gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso > /dev/null 2>&1
68
69 # disabled errexit due to gsutil setmeta complaints
70 #   BadRequestException: 400 Invalid argument
71 # check if we uploaded the file successfully to see if things are fine
72 gsutil ls gs://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso > /dev/null 2>&1
73 if [[ $? -ne 0 ]]; then
74     echo "Problem while uploading artifact!"
75     echo "Check log $WORKSPACE/gsutil.iso.log on the machine where this build is done."
76     exit 1
77 fi
78
79 echo "Done!"
80 echo
81 echo "--------------------------------------------------------"
82 echo
83 echo "Artifact is available as http://$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso"
84 echo
85 echo "--------------------------------------------------------"
86 echo