merge GIT_BRANCH and GERRIT_BRANCH into BRANCH
[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 # 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 errexit
11 set -o pipefail
12
13 echo "Host info: $(hostname) $(hostname -I)"
14
15 # Configurable environment variables:
16 # ISOSTORE (/iso_mount/opnfv_ci)
17
18 if [[ "$JOB_NAME" =~ "merge" ]]; then
19     echo "Downloading http://$GS_URL/opnfv-gerrit-$GERRIT_CHANGE_NUMBER.properties"
20     # get the properties file for the Armband Fuel ISO built for a merged change
21     curl -f -s -o $WORKSPACE/latest.properties http://$GS_URL/opnfv-gerrit-$GERRIT_CHANGE_NUMBER.properties
22 else
23     # get the latest.properties file in order to get info regarding latest artifact
24     echo "Downloading http://$GS_URL/latest.properties"
25     curl -f -s -o $WORKSPACE/latest.properties http://$GS_URL/latest.properties
26 fi
27
28 # source the file so we get artifact metadata, it will exit if it doesn't exist
29 source latest.properties
30
31 # echo the info about artifact that is used during the deployment
32 OPNFV_ARTIFACT=${OPNFV_ARTIFACT_URL/*\/}
33 echo "Using $OPNFV_ARTIFACT for deployment"
34
35 # Releng doesn't want us to use anything but opnfv.iso for now. We comply.
36 ISO_FILE=${WORKSPACE}/opnfv.iso
37
38 # using ISOs for verify & merge jobs from local storage will be enabled later
39 if [[ ! "$JOB_NAME" =~ (verify|merge) ]]; then
40     # check if we already have the ISO to avoid redownload
41     ISOSTORE=${ISOSTORE:-/iso_mount/opnfv_ci}/${BRANCH##*/}
42     if [[ -f "$ISOSTORE/$OPNFV_ARTIFACT" ]]; then
43         echo "ISO exists locally. Skipping the download and using the file from ISO store"
44         ln -s $ISOSTORE/$OPNFV_ARTIFACT ${ISO_FILE}
45         echo "--------------------------------------------------------"
46         echo
47         ls -al ${ISO_FILE}
48         echo
49         echo "--------------------------------------------------------"
50         echo "Done!"
51         exit 0
52     fi
53 fi
54
55 # Use gsutils if available
56 if $(which gsutil &>/dev/null); then
57     DOWNLOAD_URL="gs://$OPNFV_ARTIFACT_URL"
58     CMD="gsutil cp ${DOWNLOAD_URL} ${ISO_FILE}"
59 else
60     # download image
61     # -f returns error if the file was not found or on server error
62     DOWNLOAD_URL="http://$OPNFV_ARTIFACT_URL"
63     CMD="curl -f -s -o ${ISO_FILE} ${DOWNLOAD_URL}"
64 fi
65
66 # log info to console
67 echo "Downloading the $INSTALLER_TYPE artifact using URL $DOWNLOAD_URL"
68 echo "This could take some time..."
69 echo "--------------------------------------------------------"
70 echo "$CMD"
71 $CMD
72 echo "--------------------------------------------------------"
73 echo "Done!"