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