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