Merge "Increase the disk in the infracloud vms"
[releng.git] / jjb / armband / build.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Ericsson AB and others.
5 # Copyright (c) 2016 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 nounset
13 set -o pipefail
14
15 echo "Host info: $(hostname) $(hostname -I)"
16
17 cd $WORKSPACE
18
19 # Armband requires initializing git submodules (e.g. for Fuel's clean_cache.sh)
20 make submodules-init
21
22 # remove the expired items from cache
23 test -f $WORKSPACE/ci/clean_cache.sh && $WORKSPACE/ci/clean_cache.sh $CACHE_DIRECTORY
24
25 LATEST_ISO_PROPERTIES=$WORKSPACE/latest.iso.properties
26 if [[ "$JOB_NAME" =~ "daily" ]]; then
27     # check to see if we already have an artifact on artifacts.opnfv.org
28     # for this commit during daily builds
29     echo "Checking to see if we already built and stored Armband Fuel ISO for this commit"
30
31     curl -s -o $LATEST_ISO_PROPERTIES http://$GS_URL/latest.properties 2>/dev/null
32
33     # get metadata of latest ISO
34     LATEST_ISO_SHA1=$(grep OPNFV_GIT_SHA1 $LATEST_ISO_PROPERTIES | cut -d'=' -f2)
35     LATEST_ISO_URL=$(grep OPNFV_ARTIFACT_URL $LATEST_ISO_PROPERTIES | cut -d'=' -f2)
36 else
37     LATEST_ISO_SHA1=none
38 fi
39
40 # get current SHA1
41 CURRENT_SHA1=$(git rev-parse HEAD)
42
43 # set FORCE_BUILD to false for non-daily builds
44 FORCE_BUILD=${FORCE_BUILD:-false}
45
46 if [[ "$CURRENT_SHA1" == "$LATEST_ISO_SHA1" && "$FORCE_BUILD" == "false" ]]; then
47     echo "***************************************************"
48     echo "   An ISO has already been built for this commit"
49     echo "   $LATEST_ISO_URL"
50     echo "***************************************************"
51 else
52     echo "This commit has not been built yet or forced build! Proceeding with the build."
53     /bin/rm -f $LATEST_ISO_PROPERTIES
54     echo
55 fi
56
57 # log info to console
58 echo "Starting the build of Armband $INSTALLER_TYPE. This could take some time..."
59 echo "-----------------------------------------------------------"
60 echo
61
62 # create the cache directory if it doesn't exist
63 mkdir -p $CACHE_DIRECTORY
64
65 # set OPNFV_ARTIFACT_VERSION
66 if [[ "$JOB_NAME" =~ "merge" ]]; then
67     echo "Building Fuel ISO for a merged change"
68     export OPNFV_ARTIFACT_VERSION="gerrit-$GERRIT_CHANGE_NUMBER"
69     echo "Not supported"
70     exit 1
71 else
72     export OPNFV_ARTIFACT_VERSION=$(date -u +"%Y-%m-%d_%H-%M-%S")
73 fi
74
75 NOCACHE_PATTERN="verify: no-cache"
76 if [[ "$JOB_NAME" =~ "verify" && "$GERRIT_CHANGE_COMMIT_MESSAGE" =~ "$NOCACHE_PATTERN" ]]; then
77     echo "The cache will not be used for this build!"
78     NOCACHE_ARG="-f P"
79 fi
80 NOCACHE_ARG=${NOCACHE_ARG:-}
81
82 # start the build
83 cd $WORKSPACE/ci
84 ./build.sh -v $OPNFV_ARTIFACT_VERSION $NOCACHE_ARG -c file://$CACHE_DIRECTORY $BUILD_DIRECTORY
85
86 # list the build artifacts
87 ls -al $BUILD_DIRECTORY
88
89 # save information regarding artifact into file
90 (
91     echo "OPNFV_ARTIFACT_VERSION=$OPNFV_ARTIFACT_VERSION"
92     echo "OPNFV_GIT_URL=$(git config --get remote.origin.url)"
93     echo "OPNFV_GIT_SHA1=$(git rev-parse HEAD)"
94     echo "OPNFV_ARTIFACT_URL=$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso"
95     echo "OPNFV_BUILD_URL=$BUILD_URL"
96 ) > $WORKSPACE/opnfv.properties
97
98 echo
99 echo "--------------------------------------------------------"
100 echo "Done!"