3 # Copyright (c) 2021 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 echo "---> jjb/scripts/packagecloud_push.sh"
20 line="*************************************************************************"
22 # Nothing was built if this is a merge job being run when
23 # the git HEAD id is not the same as the Gerrit New Revision ID
24 if [[ ${JOB_NAME} == *merge* ]] && [ -n "${GERRIT_NEWREV:-}" ] &&
25 [ "$GERRIT_NEWREV" != "$GIT_COMMIT" ] ; then
26 echo -e "\n$line\nSkipping package push. A newer patch has been merged.\n$line\n"
31 if [ "${DRYRUN,,}" = "true" ] ; then
32 echo -e "\n$line\nSkipping package push because DRYRUN is '${DRYRUN,,}'.\n$line\n"
36 echo "STARTING PACKAGECLOUD PUSH"
40 FACTER_OS=$(/usr/bin/facter operatingsystem)
44 downloads_dir="/root/Downloads"
46 create_deb_push_cmds()
50 if [ "$distro" = "debian" ] || [ "$distro" = "ubuntu" ] ; then
51 FACTER_LSBNAME=$(/usr/bin/facter lsbdistcodename)
52 DEBS=$(find . -type f -iname '*.deb' | grep -v vpp-ext-deps | xargs || true)
53 push_cmd="package_cloud push ${PCIO_CO}/${STREAM}/${distro}/${FACTER_LSBNAME}/main/ ${DEBS}"
54 ext_deps_ver="$(dpkg -l vpp-ext-deps | mawk '/vpp-ext-deps/{print $3}' || true)"
55 ext_deps_pkg="$(find . -type f -iname 'vpp-ext-deps*.deb' | grep $ext_deps_ver || find $downloads_dir -type f -iname 'vpp-ext-deps*.deb' | grep $ext_deps_ver || true)"
56 if [ -n "$ext_deps_pkg}" ] ; then
57 push_ext_deps_cmd="package_cloud push ${PCIO_CO}/${STREAM}/${distro}/${FACTER_LSBNAME}/main/ ${ext_deps_pkg}"
60 echo "ERROR: Unknown distro: '$distro'"
65 create_rpm_push_cmds()
67 FACTER_OSMAJREL=$(/usr/bin/facter operatingsystemmajrelease)
68 FACTER_ARCH=$(/usr/bin/facter architecture)
69 RPMS=$(find . -type f -iregex '.*/.*\.\(s\)?rpm' | grep -v vpp-ext-deps | xargs || true)
70 push_cmd="package_cloud push ${PCIO_CO}/${STREAM}/el/${FACTER_OSMAJREL}/os/${FACTER_ARCH}/ ${RPMS}"
71 ext_deps_ver="$(dnf list vpp-ext-deps | mawk '/vpp-ext-deps/{print $2}' || true)"
72 ext_deps_pkg="$(find . -type f -iname 'vpp-ext-deps*.rpm' | grep $ext_deps_ver || find $downloads_dir -type f -iname 'vpp-ext-deps*.rpm' | grep $ext_deps_ver || true)"
73 if [ -n "$ext_deps_pkg" ] ; then
74 push_ext_deps_cmd="package_cloud push ${PCIO_CO}/${STREAM}/el/${FACTER_OSMAJREL}/os/${FACTER_ARCH}/ ${ext_deps_pkg}"
78 # PCIO_CO and SILO are Jenkins Global Environment variables defined in
79 # .../ci-management/jenkins-config/global-vars-*.sh
80 if [ -f ~/.packagecloud ]; then
83 create_deb_push_cmds debian
86 create_deb_push_cmds ubuntu
92 echo -e "\n$line\n* ERROR: Unsupported OS '$FACTER_OS'\n* PACKAGECLOUD PUSH FAILED!\n$line\n"
96 if [ "${SILO,,}" = "sandbox" ] ; then
97 echo "SANDBOX: skipping '$push_cmd'"
98 if [ -n "$push_ext_deps_cmd" ] ; then
99 echo "SANDBOX: skipping '$push_ext_deps_cmd'"
103 if [ -n "$push_ext_deps_cmd" ] ; then
104 $push_ext_deps_cmd || true
108 echo "ERROR: Missing '~/.packagecloud' for user '$(id)'"
109 echo "PACKAGECLOUD PUSH FAILED!"
113 echo -e "\n$line\n* PACKAGECLOUD PUSH COMPLETE\n$line\n"