run Functest daily in xci
[releng.git] / jjb / armband / armband-download-artifact.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Ericsson AB and others.
5 #           (c) 2017 Enea AB
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11 set -o errexit
12 set -o pipefail
13
14 # disable Fuel ISO download for master branch
15 [[ "$BRANCH" == 'master' ]] && exit 0
16
17 echo "Host info: $(hostname) $(hostname -I)"
18
19 # Configurable environment variables:
20 # ISOSTORE (/iso_mount/opnfv_ci)
21
22 if [[ "$JOB_NAME" =~ "merge" ]]; then
23     echo "Downloading http://$GS_URL/opnfv-gerrit-$GERRIT_CHANGE_NUMBER.properties"
24     # get the properties file for the Armband Fuel ISO built for a merged change
25     curl -f -s -o $WORKSPACE/latest.properties http://$GS_URL/opnfv-gerrit-$GERRIT_CHANGE_NUMBER.properties
26 else
27     # get the latest.properties file in order to get info regarding latest artifact
28     echo "Downloading http://$GS_URL/latest.properties"
29     curl -f -s -o $WORKSPACE/latest.properties http://$GS_URL/latest.properties
30 fi
31
32 # source the file so we get artifact metadata, it will exit if it doesn't exist
33 source latest.properties
34
35 # echo the info about artifact that is used during the deployment
36 OPNFV_ARTIFACT=${OPNFV_ARTIFACT_URL/*\/}
37 echo "Using $OPNFV_ARTIFACT for deployment"
38
39 # Releng doesn't want us to use anything but opnfv.iso for now. We comply.
40 ISO_FILE=${WORKSPACE}/opnfv.iso
41
42 # using ISOs for verify & merge jobs from local storage will be enabled later
43 if [[ ! "$JOB_NAME" =~ (verify|merge) ]]; then
44     # check if we already have the ISO to avoid redownload
45     ISOSTORE=${ISOSTORE:-/iso_mount/opnfv_ci}/${BRANCH##*/}
46     if [[ -f "$ISOSTORE/$OPNFV_ARTIFACT" ]]; then
47         echo "ISO exists locally. Skipping the download and using the file from ISO store"
48         ln -s $ISOSTORE/$OPNFV_ARTIFACT ${ISO_FILE}
49         echo "--------------------------------------------------------"
50         echo
51         ls -al ${ISO_FILE}
52         echo
53         echo "--------------------------------------------------------"
54         echo "Done!"
55         exit 0
56     fi
57 fi
58
59 # Use gsutils if available
60 if $(which gsutil &>/dev/null); then
61     DOWNLOAD_URL="gs://$OPNFV_ARTIFACT_URL"
62     CMD="gsutil cp ${DOWNLOAD_URL} ${ISO_FILE}"
63 else
64     # download image
65     # -f returns error if the file was not found or on server error
66     DOWNLOAD_URL="http://$OPNFV_ARTIFACT_URL"
67     CMD="curl -f -s -o ${ISO_FILE} ${DOWNLOAD_URL}"
68 fi
69
70 # log info to console
71 echo "Downloading the $INSTALLER_TYPE artifact using URL $DOWNLOAD_URL"
72 echo "This could take some time..."
73 echo "--------------------------------------------------------"
74 echo "$CMD"
75 $CMD
76 echo "--------------------------------------------------------"
77 echo "Done!"