Merge "Job for testing the ODL user configuration"
[releng/builder.git] / jjb / packaging / build-rpm.sh
1 #!/bin/bash
2
3 # Options:
4 #   -x: Echo commands
5 #   -e: Fail on errors
6 #   -o pipefail: Fail on errors in scripts this calls, give stacktrace
7 set -ex -o pipefail
8
9 # Install required packages
10 virtualenv rpm_build
11 # shellcheck disable=SC1091
12 source rpm_build/bin/activate
13 PYTHON="rpm_build/bin/python"
14 $PYTHON -m pip install --upgrade pip
15 $PYTHON -m pip install -r "$WORKSPACE/packaging/packages/requirements.txt"
16
17 # Verify artifact at DOWNLOAD_URL exists
18 # shellcheck disable=SC2154
19 url_status=$(curl --silent --head --location --output /dev/null --write-out \
20   '%{http_code}' "$DOWNLOAD_URL")
21 if [[ $url_status = 2* ]]; then
22   echo "Artifact at DOWNLOAD_URL exists"
23 else
24   echo "Artifact at DOWNLOAD_URL does not exist"
25   exit 1
26 fi
27
28
29 # Packaging logic needs a tarball, but can repackage a zip into tar.gz
30 # if needed. All builds except multipatch-test publish both a tar.gz and zip.
31 # Autorelease passes DOWNLOAD_URL to zip, others typically use tar.gz.
32 # If URL is to zip, check if there's a tar.gz available to avoid repackaging.
33 if [[ $DOWNLOAD_URL = *.zip ]]; then
34   # shellcheck disable=SC2154
35   candidate_tarball_url="${DOWNLOAD_URL//zip/tar.gz}"
36   # shellcheck disable=SC2154
37   url_status=$(curl --silent --head --location --output /dev/null --write-out \
38     '%{http_code}' "$candidate_tarball_url")
39   if [[ $url_status = 2* ]]; then
40     DOWNLOAD_URL="$candidate_tarball_url"
41   fi
42 fi
43
44 # Build release specified by build params
45 "$WORKSPACE/packaging/packages/build.py" --rpm \
46                                          --changelog_name "$CHANGELOG_NAME" \
47                                          --changelog_email "$CHANGELOG_EMAIL" \
48                                          direct \
49                                          --download_url "$DOWNLOAD_URL"
50
51 # Always allow push to scratch repos, only push to CD repos in RelEng Jenkins
52 if [ "$DEPLOY_TO_REPO" == "opendaylight-epel-7-x86_64-devel" ]; then
53   # Move RPMs (SRPM and noarch) to dir of files that will be uploaded to Nexus
54   UPLOAD_FILES_PATH="$WORKSPACE/upload_files"
55   mkdir -p "$UPLOAD_FILES_PATH"
56   cp "$HOME/rpmbuild/RPMS/noarch/"*.rpm "$_"
57   cp "$HOME/rpmbuild/SRPMS/"*.rpm "$_"
58 else
59   # Publish RPMs to CD repos if in production Jenkins, not in sandbox Jenkins
60   if [ "$SILO" == "sandbox" ]; then
61     echo "Not uploading RPMs to Nexus because running in sandbox"
62   elif  [ "$SILO" == "releng" ]; then
63     # Move RPMs (SRPM+noarch) to dir of files that will be uploaded to Nexus
64     UPLOAD_FILES_PATH="$WORKSPACE/upload_files"
65     mkdir -p "$UPLOAD_FILES_PATH"
66     cp "$HOME/rpmbuild/RPMS/noarch/"*.rpm "$_"
67     cp "$HOME/rpmbuild/SRPMS/"*.rpm "$_"
68   else
69     echo "Unknown Jenkins silo: $SILO"
70     exit 1
71   fi
72 fi