Fix propogation of build errors.
[ci-management.git] / jjb / vpp / include-raw-vpp-maven-push.sh
1 #!/bin/bash
2 set -xeu -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 # Determine the path to maven
9 if [ -z "${MAVEN_SELECTOR}" ]; then
10     echo "ERROR: No Maven install detected!"
11     exit 1
12 fi
13
14 MVN="${HOME}/tools/hudson.tasks.Maven_MavenInstallation/${MAVEN_SELECTOR}/bin/mvn"
15 GROUP_ID="io.fd.${PROJECT}"
16 BASEURL="${NEXUSPROXY}/content/repositories/fd.io."
17 BASEREPOID='fdio-'
18
19 function push_file ()
20 {
21     push_file=$1
22     repoId=$2
23     url=$3
24     version=$4
25     artifactId=$5
26     file_type=$6
27     classifier=$7
28
29     if [ "$classifier" ]; then
30         d_classifier="-Dclassifier=$7"
31     fi
32
33     # Disable checks for doublequote to prevent glob / splitting
34     # shellcheck disable=SC2086
35     $MVN org.apache.maven.plugins:maven-deploy-plugin:deploy-file \
36         -Dfile=$push_file -DrepositoryId=$repoId \
37         -Durl=$url -DgroupId=$GROUP_ID \
38         -Dversion=$version -DartifactId=$artifactId \
39         -Dtype=$file_type $d_classifier\
40         -gs $GLOBAL_SETTINGS_FILE -s $SETTINGS_FILE
41
42     # make sure the script bombs if we fail an upload
43     if [ "$?" != '0' ]; then
44         echo "ERROR: There was an error with the upload"
45         exit 1
46     fi
47 }
48
49 function push_jar ()
50 {
51     jarfile=$1
52     repoId="${BASEREPOID}snapshot"
53     url="${BASEURL}snapshot"
54
55     basefile=$(basename -s .jar "$jarfile")
56     artifactId=$(echo "$basefile" | cut -f 1 -d '-')
57     version=$(echo "$basefile" | cut -f 2 -d '-')
58
59     push_file "$jarfile" "$repoId" "$url" "${version}-SNAPSHOT" "$artifactId" jar
60 }
61
62 function push_deb ()
63 {
64     debfile=$1
65     repoId="fd.io.${REPO_NAME}"
66     url="${BASEURL}${REPO_NAME}"
67
68     basefile=$(basename -s .deb "$debfile")
69     artifactId=$(echo "$basefile" | cut -f 1 -d '_')
70     version=$(echo "$basefile" | cut -f 2- -d '_')
71
72     push_file "$debfile" "$repoId" "$url" "$version" "$artifactId" deb
73 }
74
75 function push_rpm ()
76 {
77     rpmfile=$1
78     repoId="fd.io.${REPO_NAME}"
79     url="${BASEURL}${REPO_NAME}"
80
81     if grep -qE '\.s(rc\.)?rpm' <<<"$rpmfile"
82     then
83         rpmrelease=$(rpm -qp --queryformat="%{release}.src" "$rpmfile")
84     else
85         rpmrelease=$(rpm -qp --queryformat="%{release}.%{arch}" "$rpmfile")
86     fi
87     artifactId=$(rpm -qp --queryformat="%{name}" "$rpmfile")
88     version=$(rpm -qp --queryformat="%{version}" "$rpmfile")
89     push_file "$rpmfile" "$repoId" "$url" "${version}-${rpmrelease}" "$artifactId" rpm
90 }
91
92 if [ "${OS}" == "ubuntu1404" ]; then
93     # Find the files
94     JARS=$(find . -type f -iname '*.jar')
95     DEBS=$(find . -type f -iname '*.deb')
96     for i in $JARS
97     do
98         push_jar "$i"
99     done
100
101     for i in $DEBS
102     do
103         push_deb "$i"
104     done
105 elif [ "${OS}" == "ubuntu1604" ]; then
106     DEBS=$(find . -type f -iname '*.deb')
107     for i in $DEBS
108     do
109         push_deb "$i"
110     done
111 elif [ "${OS}" == "centos7" ]; then
112     # Find the files
113     RPMS=$(find . -type f -iname '*.rpm')
114     SRPMS=$(find . -type f -iname '*.srpm')
115     SRCRPMS=$(find . -type f -name '*.src.rpm')
116     for i in $RPMS $SRPMS $SRCRPMS
117     do
118         push_rpm "$i"
119     done
120 fi
121 # vim: ts=4 sw=4 sts=4 et ft=sh :