Add quick verify job for RPM building logic
[releng/builder.git] / jjb / packaging / build-rpm-snap.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 # If STREAM not passed, extract from job name (format: foo-job-name-<stream>)
18 if [ -z "$STREAM" ]; then
19   # shellcheck disable=SC1083
20   STREAM=${{JOB_NAME##*-}}
21 fi
22
23 # Convert stream to numeric ODL major version
24 if [ "$STREAM" == "boron" ]; then
25   VERSION_MAJOR=5
26 elif [ "$STREAM" == "carbon" ]; then
27   VERSION_MAJOR=6
28 elif [ "$STREAM" == "nitrogen" ]; then
29   VERSION_MAJOR=7
30 elif [ "$STREAM" == "oxygen" ]; then
31   VERSION_MAJOR=8
32 else
33   echo "Unable to convert stream to major version"
34   exit 1
35 fi
36
37 # Build the latest snapshot matching the given major minor version
38 "$WORKSPACE/packaging/packages/build.py" --rpm \
39                                          --changelog_name "$CHANGELOG_NAME" \
40                                          --changelog_email "$CHANGELOG_EMAIL" \
41                                          latest_snap \
42                                          --major "$VERSION_MAJOR"
43
44 # Publish RPMs to Nexus if in production Jenkins, else host on sandbox Jenkins
45 if [ "$SILO" == "sandbox" ]; then
46   # TODO: Host RPMs on Jenkins temporarily
47   echo "Not uploading RPMs to Nexus because running in sandbox"
48 elif  [ "$SILO" == "releng" ]; then
49   # Move RPMs (SRPM and noarch) to dir of files that will be uploaded to Nexus
50   UPLOAD_FILES_PATH="$WORKSPACE/upload_files"
51   mkdir -p "$UPLOAD_FILES_PATH"
52   mv "/home/$USER/rpmbuild/RPMS/noarch/"*.rpm "$_"
53   mv "/home/$USER/rpmbuild/SRPMS/"*.rpm "$_"
54 else
55   echo "Unknown Jenkins silo: $SILO"
56   exit 1
57 fi