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