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