Extend packagecloud-push for build-dir

Extend script packagecloud-push.sh with environment variable BUILD_DIR.
Populate BUILD_DIR from JJB config parameter build-dir, required for
cmake anyhow.  This limits the search to a single directory.

Add build-dir default to docker-ci template, "export-packages"

Revise export script to use a constant value for build-dir,
also "export-packages" in $WORKSPACE.

Signed-off-by: Lott, Christopher (cl778h) <cl778h@att.com>
Change-Id: I3da170246fb5868e644756e80c20b07bf68f55f9
diff --git a/jjb/oran-templates/oran-c-cpp-jobs.yaml b/jjb/oran-templates/oran-c-cpp-jobs.yaml
index 386b513..c43e735 100644
--- a/jjb/oran-templates/oran-c-cpp-jobs.yaml
+++ b/jjb/oran-templates/oran-c-cpp-jobs.yaml
@@ -68,7 +68,7 @@
 
     branch: master
     build-days-to-keep: 7
-    build-dir: "$WORKSPACE/target"
+    build-dir: "$WORKSPACE/build"
     build-timeout: 15
     cmake-opts: ""
     cron: "" # avoid for PackageCloud which rejects duplicates
@@ -99,6 +99,7 @@
       - shell: "{pre-build}"
       - shell: !include-raw-escape: ../../global-jjb/shell/cmake-build.sh
       - oran-packagecloud-push:
+          build-dir: "{build-dir}"
           packagecloud-account: "{packagecloud-account}"
           packagecloud-repo: "{packagecloud-repo}"
           debian-distribution-versions: "{debian-distribution-versions}"
diff --git a/jjb/oran-templates/oran-docker-ci-jobs.yaml b/jjb/oran-templates/oran-docker-ci-jobs.yaml
index 601aee1..93c431b 100644
--- a/jjb/oran-templates/oran-docker-ci-jobs.yaml
+++ b/jjb/oran-templates/oran-docker-ci-jobs.yaml
@@ -132,6 +132,7 @@
       - shell: "{post_docker_build_script}"
       - oran-docker-build-export
       - oran-packagecloud-push:
+          build-dir: export-packages # directory with deb/rpm files
           packagecloud-account: "{packagecloud-account}"
           packagecloud-repo: "{packagecloud-repo}"
           debian-distribution-versions: "{debian-distribution-versions}"
diff --git a/jjb/oran-templates/oran-package-cloud-macros.yaml b/jjb/oran-templates/oran-package-cloud-macros.yaml
index 2005d57..cca7720 100644
--- a/jjb/oran-templates/oran-package-cloud-macros.yaml
+++ b/jjb/oran-templates/oran-package-cloud-macros.yaml
@@ -13,9 +13,8 @@
 #   See the License for the specific language governing permissions and
 #   limitations under the License.
 
-# Macros to invoke shell scripts for PackageCloud
-
 - builder:
+    # provisions files required by package_cloud ruby gem
     name: oran-packagecloud-file-provider
     builders:
       - config-file-provider:
@@ -28,6 +27,8 @@
               target: "$HOME/packagecloud_api"
 
 - builder:
+    # Runs shell script to push packages to PackageCloud.
+    # {build-dir} is directory with deb/rpm files to push
     # {packagecloud-account} is PackageCloud account ID; example: oran
     # {packagecloud-repo} is PackageCloud repository; example: master, staging
     # {debian-distribution-versions} is list of DEB package distro/version strings
@@ -38,9 +39,9 @@
     builders:
       - inject:
           properties-content: |
+            BUILD_DIR={build-dir}
             PACKAGECLOUD_ACCOUNT={packagecloud-account}
             PACKAGECLOUD_REPO={packagecloud-repo}
             DEBIAN_DISTRIBUTION_VERSIONS={debian-distribution-versions}
             RPM_DISTRIBUTION_VERSIONS={rpm-distribution-versions}
-      - shell: !include-raw-escape:
-          - ../shell/packagecloud-push.sh
+      - shell: !include-raw-escape: ../shell/packagecloud-push.sh
diff --git a/jjb/ric-plt-xapp-frame-cpp/ric-plt-xapp-frame-cpp.yaml b/jjb/ric-plt-xapp-frame-cpp/ric-plt-xapp-frame-cpp.yaml
index 5fd387b..9bbd431 100644
--- a/jjb/ric-plt-xapp-frame-cpp/ric-plt-xapp-frame-cpp.yaml
+++ b/jjb/ric-plt-xapp-frame-cpp/ric-plt-xapp-frame-cpp.yaml
@@ -29,14 +29,27 @@
     # install RMR per version file in repo for ubuntu
     pre-build: !include-raw-escape:
       - ../shell/install-deb-rmr3.sh
-    # verify and sonar use cmake
-    cmake-opts: -DDEV_PKG=1
-    make-opts: install test ARGS=-V
 
-# verify on changes, publish on stage
+# development library - publish only
 - project:
-    name: xapp-frame-cpp-verify
+    name: xapp-frame-cpp-lib-dev
     <<: *xapp_frame_cpp_common
+    project-name: ric-plt-xapp-frame-cpp-dev
+    cmake-opts: -DDEV_PKG=1
+    make-opts: package ARGS=-V
+    jobs:
+      - oran-gerrit-cmake-pc-stage
+    stream:
+      - master:
+          branch: master
+
+# runtime library - test and publish
+- project:
+    name: xapp-frame-cpp-lib-rt
+    <<: *xapp_frame_cpp_common
+    project-name: ric-plt-xapp-frame-cpp-lib
+    cmake-opts: -DDEV_PKG=0
+    make-opts: test package ARGS=-V
     jobs:
       - gerrit-cmake-verify
       - oran-gerrit-cmake-pc-stage
@@ -48,6 +61,7 @@
 - project:
     name: xapp-frame-cpp-sonarqube
     <<: *xapp_frame_cpp_common
+    make-opts: test ARGS=-V
     sonar-project-file: ""
     sonar-properties: |
         sonar.login={sonarcloud_api_token}
diff --git a/jjb/shell/export-packages.sh b/jjb/shell/export-packages.sh
index e6bf076..12c6364 100755
--- a/jjb/shell/export-packages.sh
+++ b/jjb/shell/export-packages.sh
@@ -23,8 +23,10 @@
 # that copies artifacts created by the builder to a directory.
 # Environment variables are injected in previous Jenkins steps.
 # The push script searches the workspace, so do not use /tmp etc.
-HOST=$WORKSPACE/export-packages-$$
+HOST=$WORKSPACE/export-packages
 GUEST=/export
 mkdir -p "$HOST"
 docker run -v "$HOST":"$GUEST" "$CONTAINER_PUSH_REGISTRY"/"$DOCKER_NAME":"$DOCKER_IMAGE_TAG" "$GUEST"
 ls "$HOST"
+
+echo "--> export-packages.sh ends"
diff --git a/jjb/shell/packagecloud-push.sh b/jjb/shell/packagecloud-push.sh
index a48d39c..beb9467 100755
--- a/jjb/shell/packagecloud-push.sh
+++ b/jjb/shell/packagecloud-push.sh
@@ -1,41 +1,53 @@
 #!/bin/bash -l
 # SPDX-License-Identifier: EPL-1.0
 ##############################################################################
-# Copyright (c) 2019 The Linux Foundation and others.
+# Copyright (c) 2020 The Linux Foundation and others.
 #
 # All rights reserved. This program and the accompanying materials
 # are made available under the terms of the Eclipse Public License v1.0
 # which accompanies this distribution, and is available at
 # http://www.eclipse.org/legal/epl-v10.html
 ##############################################################################
+
+# Prereqs:
+# The build minion has the ruby gem "package_cloud"
+# The required credentials and API files have been provisioned
+# The build directory has .deb/.rpm files
+# Environment variables:
+# BUILD_DIR is set and non-empty
+# DEBIAN_DISTRIBUTION_VERSIONS has distro list like "debian/stretch"
+# RPM_DISTRIBUTION_VERSIONS has distro list like "el/4 el/5"
+# PACKAGECLOUD_ACCOUNT is set and non-empty
+# PACKAGECLOUD_REPO is a value like "staging"
+
 echo "---> packagecloud-push.sh"
 set -eu -o pipefail
 
-if [ ! -f ~/.packagecloud ]; then
-    echo "INFO: .packagecloud file not found"
-    exit 0
-fi
-
- # For DEB
-vers=("$DEBIAN_DISTRIBUTION_VERSIONS")
-echo "Debian distribution versions:" "${vers[@]}"
-debs=$(find . -type f -iname '*.deb')
-# modern bash syntax is helpful
-for (( i = 0; i < ${#vers[@]}; i++ )); do
-    for deb in $debs; do
-       echo "Pushing $deb $PACKAGECLOUD_ACCOUNT/$PACKAGECLOUD_REPO/${vers[i]}"
-       package_cloud push "$PACKAGECLOUD_ACCOUNT"/"$PACKAGECLOUD_REPO"/"${vers[i]}" "$deb"
+# Pushes packages to PackageCloud
+# $1 is a shell-style glob pattern for package files
+# $2 is a space-separated list of distribution versions
+push_packages () {
+    echo "Expanding file pattern $1"
+    # shellcheck disable=SC2206
+    pkgs=($1)
+    if [[ ! -f ${pkgs[0]} ]]; then
+        echo "WARN: no files matched pattern $1"
+        return
+    fi
+    echo "Found package file(s):" "${pkgs[@]}"
+    echo "Processing distribution version(s): $2"
+    for ver in $2; do
+        arg="${PACKAGECLOUD_ACCOUNT}/${PACKAGECLOUD_REPO}/${ver}"
+        for pkg in "${pkgs[@]}"; do
+            echo "Pushing $arg $pkg"
+            package_cloud push "$arg" "$pkg"
+        done
     done
-done
+}
 
-# For RPM
-vers=("$RPM_DISTRIBUTION_VERSIONS")
-echo "RPM distribution versions:" "${vers[@]}"
-rpms=$(find . -type f -iregex '.*/.*\.\(s\)?rpm')
-# modern bash syntax is helpful
-for (( i = 0; i < ${#vers[@]}; i++ )); do
-    for rpm in $rpms; do
-       echo "Pushing $rpm $PACKAGECLOUD_ACCOUNT/$PACKAGECLOUD_REPO/${vers[i]}"
-       package_cloud push "$PACKAGECLOUD_ACCOUNT"/"$PACKAGECLOUD_REPO"/"${vers[i]}" "$rpm"
-    done
-done
+echo "Working in directory $BUILD_DIR"
+cd "$BUILD_DIR"
+push_packages "*.deb" "$DEBIAN_DISTRIBUTION_VERSIONS"
+push_packages "*.rpm" "$RPM_DISTRIBUTION_VERSIONS"
+
+echo "---> packagecloud-push.sh ends"