Merge "Adding a new verification job for testapi UI."
[releng.git] / jjb / apex / apex-build.sh
1 #!/bin/bash
2 set -o errexit
3 set -o nounset
4 set -o pipefail
5 # log info to console
6 echo "Starting the build of Apex using OpenStack Master packages. This will take some time..."
7 echo "---------------------------------------------------------------------------------------"
8 echo
9 # create the cache directory if it doesn't exist
10 [[ -d $CACHE_DIRECTORY ]] || mkdir -p $CACHE_DIRECTORY
11 # set OPNFV_ARTIFACT_VERSION
12 if echo $ARTIFACT_VERSION | grep "dev" 1> /dev/null; then
13   GERRIT_PATCHSET_NUMBER=$(echo $GERRIT_REFSPEC | grep -Eo '[0-9]+$')
14   export OPNFV_ARTIFACT_VERSION="dev${GERRIT_CHANGE_NUMBER}_${GERRIT_PATCHSET_NUMBER}"
15   if [[ "$BRANCH" != 'stable/fraser' ]]; then
16     # build rpm
17     export BUILD_ARGS="-r $OPNFV_ARTIFACT_VERSION -c $CACHE_DIRECTORY --rpms"
18   else
19     export BUILD_ARGS="-r $OPNFV_ARTIFACT_VERSION -c $CACHE_DIRECTORY"
20   fi
21 elif echo $BUILD_TAG | grep "csit" 1> /dev/null; then
22   export OPNFV_ARTIFACT_VERSION=csit${BUILD_NUMBER}
23   export BUILD_ARGS="-r $OPNFV_ARTIFACT_VERSION -c $CACHE_DIRECTORY"
24 elif [ "$ARTIFACT_VERSION" == "daily" ]; then
25   export OPNFV_ARTIFACT_VERSION=$(date -u +"%Y-%m-%d")
26   if [[ "$BRANCH" != 'stable/fraser' ]]; then
27     export BUILD_ARGS="-r $OPNFV_ARTIFACT_VERSION -c $CACHE_DIRECTORY --rpms"
28   else
29     export BUILD_ARGS="-r $OPNFV_ARTIFACT_VERSION -c $CACHE_DIRECTORY --iso"
30   fi
31 else
32   export OPNFV_ARTIFACT_VERSION=${ARTIFACT_VERSION}
33   if [[ "$BRANCH" != 'stable/fraser' ]]; then
34     export BUILD_ARGS="-r $OPNFV_ARTIFACT_VERSION -c $CACHE_DIRECTORY --rpms"
35   else
36     export BUILD_ARGS="-r $OPNFV_ARTIFACT_VERSION -c $CACHE_DIRECTORY --iso"
37   fi
38 fi
39
40 # Temporary hack until we fix apex build script
41 BUILD_DIRECTORY=${WORKSPACE}/build
42
43 # start the build
44 pushd ${BUILD_DIRECTORY}
45 make clean
46 popd
47 export PYTHONPATH=${WORKSPACE}
48 python3 apex/build.py $BUILD_ARGS
49 RPM_VERSION=$(grep Version: $WORKSPACE/build/rpm_specs/opnfv-apex.spec | awk '{ print $2 }')-$(echo $OPNFV_ARTIFACT_VERSION | tr -d '_-')
50 # list the contents of BUILD_OUTPUT directory
51 echo "Build Directory is ${BUILD_DIRECTORY}/../.build"
52 echo "Build Directory Contents:"
53 echo "-------------------------"
54 ls -al ${BUILD_DIRECTORY}/../.build
55
56 # list the contents of CACHE directory
57 echo "Cache Directory is ${CACHE_DIRECTORY}"
58 echo "Cache Directory Contents:"
59 echo "-------------------------"
60 ls -al $CACHE_DIRECTORY
61
62 if [[ "$BUILD_ARGS" =~ '--iso' && "$BRANCH" == 'stable/fraser' ]]; then
63   mkdir -p /tmp/apex-iso/
64   rm -f /tmp/apex-iso/*.iso
65   cp -f $BUILD_DIRECTORY/../.build/release/OPNFV-CentOS-7-x86_64-$OPNFV_ARTIFACT_VERSION.iso /tmp/apex-iso/
66 fi
67
68 if ! echo $ARTIFACT_VERSION | grep "dev" 1> /dev/null; then
69   echo "Writing opnfv.properties file"
70   if [ "$BRANCH" == 'stable/fraser' ]; then
71     # save information regarding artifact into file
72     (
73       echo "OPNFV_ARTIFACT_VERSION=$OPNFV_ARTIFACT_VERSION"
74       echo "OPNFV_GIT_URL=$(git config --get remote.origin.url)"
75       echo "OPNFV_GIT_SHA1=$(git rev-parse HEAD)"
76       echo "OPNFV_ARTIFACT_URL=$GS_URL/opnfv-$OPNFV_ARTIFACT_VERSION.iso"
77       echo "OPNFV_ARTIFACT_SHA512SUM=$(sha512sum $BUILD_DIRECTORY/../.build/release/OPNFV-CentOS-7-x86_64-$OPNFV_ARTIFACT_VERSION.iso | cut -d' ' -f1)"
78       echo "OPNFV_SRPM_URL=$GS_URL/opnfv-apex-$RPM_VERSION.src.rpm"
79       echo "OPNFV_RPM_URL=$GS_URL/opnfv-apex-$RPM_VERSION.noarch.rpm"
80       echo "OPNFV_RPM_SHA512SUM=$(sha512sum $BUILD_DIRECTORY/../.build/noarch/opnfv-apex-$RPM_VERSION.noarch.rpm | cut -d' ' -f1)"
81       echo "OPNFV_BUILD_URL=$BUILD_URL"
82     ) > $WORKSPACE/opnfv.properties
83   else
84     # save information regarding artifact into file
85     # we only generate the python package for master
86     (
87       echo "OPNFV_ARTIFACT_VERSION=$OPNFV_ARTIFACT_VERSION"
88       echo "OPNFV_GIT_URL=$(git config --get remote.origin.url)"
89       echo "OPNFV_GIT_SHA1=$(git rev-parse HEAD)"
90       echo "OPNFV_SRPM_URL=$GS_URL/python34-opnfv-apex-$RPM_VERSION.src.rpm"
91       echo "OPNFV_RPM_URL=$GS_URL/python34-opnfv-apex-$RPM_VERSION.noarch.rpm"
92       echo "OPNFV_RPM_SHA512SUM=$(sha512sum $BUILD_DIRECTORY/../.build/noarch/python34-opnfv-apex-$RPM_VERSION.noarch.rpm | cut -d' ' -f1)"
93       echo "OPNFV_BUILD_URL=$BUILD_URL"
94     ) > $WORKSPACE/opnfv.properties
95   fi
96 fi
97 echo "--------------------------------------------------------"
98 echo "Done!"