Merge "Restore vpp-csit-*tx2 jobs in production"
[ci-management.git] / jjb / scripts / maven_push_functions.sh
1 #!/bin/bash
2
3 # Copyright (c) 2020 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:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15
16 echo "---> jjb/scripts/maven_push_functions.sh"
17
18 set -xe -o pipefail
19 echo "*******************************************************************"
20 echo "* STARTING PUSH OF PACKAGES TO REPOS"
21 echo "* NOTHING THAT HAPPENS BELOW THIS POINT IS RELATED TO BUILD FAILURE"
22 echo "*******************************************************************"
23
24 [ "$MVN" ] || MVN="/opt/apache/maven/bin/mvn"
25 GROUP_ID="io.fd.${PROJECT}"
26 BASEURL="${NEXUSPROXY}/content/repositories/fd.io."
27 BASEREPOID='fdio-'
28
29 function push_file ()
30 {
31     push_file=$1
32     repoId=$2
33     url=$3
34     version=$4
35     artifactId=$5
36     file_type=$6
37
38     if [ -n "$7" ]; then
39         d_classifier="-Dclassifier=$7"
40     fi
41
42     if [ ! -f "$push_file" ] ; then
43         echo "file for deployment does not exist: $push_file"
44         exit 1;
45     fi
46
47     # Disable checks for doublequote to prevent glob / splitting
48     # shellcheck disable=SC2086
49     $MVN -B org.apache.maven.plugins:maven-deploy-plugin:deploy-file \
50         -Dfile=$push_file -DrepositoryId=$repoId \
51         -Durl=$url -DgroupId=$GROUP_ID \
52         -Dversion=$version -DartifactId=$artifactId \
53         -Dtype=$file_type $d_classifier\
54         -gs $GLOBAL_SETTINGS_FILE -s $SETTINGS_FILE
55
56     # make sure the script bombs if we fail an upload
57     if [ "$?" != '0' ]; then
58         echo "ERROR: There was an error with the upload"
59         exit 1
60     fi
61 }
62
63 function push_jar ()
64 {
65     jarfile=$1
66     repoId="${BASEREPOID}snapshot"
67     url="${BASEURL}snapshot"
68
69     # examples:
70     # * jvpp-registry-16.09.jar
71     # * jvpp-16.09.jar
72
73     basefile=$(basename -s .jar "$jarfile")
74     artifactId=$(echo "$basefile" | rev | cut -d '-' -f 2-  | rev)
75     version=$(echo "$basefile" | rev | cut -d '-' -f 1  | rev)
76
77     push_file "$jarfile" "$repoId" "$url" "${version}-SNAPSHOT" "$artifactId" jar
78 }
79
80 function push_deb ()
81 {
82     debfile=$1
83     repoId="fd.io.${REPO_NAME}"
84     url="${BASEURL}${REPO_NAME}"
85
86     basefile=$(basename -s .deb "$debfile")
87     artifactId=$(echo "$basefile" | cut -f 1 -d '_')
88     version=$(echo "$basefile" | cut -f 2- -d '_')
89     file_type=deb
90     classifier=deb
91
92     push_file "$debfile" "$repoId" "$url" "$version" "$artifactId" "$file_type" "$classifier"
93 }
94
95 function push_rpm ()
96 {
97     rpmfile=$1
98     repoId="fd.io.${REPO_NAME}"
99     url="${BASEURL}${REPO_NAME}"
100
101     if grep -qE '\.s(rc\.)?rpm' <<<"$rpmfile"
102     then
103         rpmrelease=$(rpm -qp --queryformat="%{release}.src" "$rpmfile")
104     else
105         rpmrelease=$(rpm -qp --queryformat="%{release}.%{arch}" "$rpmfile")
106     fi
107     artifactId=$(rpm -qp --queryformat="%{name}" "$rpmfile")
108     version=$(rpm -qp --queryformat="%{version}" "$rpmfile")
109     push_file "$rpmfile" "$repoId" "$url" "${version}-${rpmrelease}" "$artifactId" rpm
110 }