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