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