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