b1f977a6f20e311c25169796c41759dc2a29c48b
[releng.git] / jjb / 3rd_party_ci / download-netvirt-artifact.sh
1 #!/bin/bash
2 set -o errexit
3 set -o nounset
4 set -o pipefail
5
6 echo "Attempting to fetch the artifact location from ODL Jenkins"
7 if [ "$ODL_BRANCH" != 'master' ]; then
8   DIST=$(echo ${ODL_BRANCH} | sed -rn 's#([a-zA-Z]+)/([a-zA-Z]+)#\2#p')
9   ODL_BRANCH=$(echo ${ODL_BRANCH} | sed -rn 's#([a-zA-Z]+)/([a-zA-Z]+)#\1%2F\2#p')
10 else
11   DIST='fluorine'
12 fi
13
14 echo "ODL Distribution is ${DIST}"
15 ODL_ZIP="karaf-SNAPSHOT.zip"
16 CHANGE_DETAILS_URL="https://git.opendaylight.org/gerrit/changes/netvirt~${ODL_BRANCH}~${GERRIT_CHANGE_ID}/detail"
17 # due to limitation with the Jenkins Gerrit Trigger, we need to use Gerrit REST API to get the change details
18 ODL_BUILD_JOB_NUM=$(curl --fail ${CHANGE_DETAILS_URL} | grep -Eo "netvirt-distribution-check-${DIST}/[0-9]+" | tail -1 | grep -Eo [0-9]+)
19 DISTRO_CHECK_CONSOLE_LOG="https://logs.opendaylight.org/releng/vex-yul-odl-jenkins-1/netvirt-distribution-check-${DIST}/${ODL_BUILD_JOB_NUM}/console.log.gz"
20 NETVIRT_ARTIFACT_URL=$(curl --fail --compressed ${DISTRO_CHECK_CONSOLE_LOG} | grep 'BUNDLE_URL' | cut -d = -f 2)
21
22 echo -e "URL to artifact is\n\t$NETVIRT_ARTIFACT_URL"
23
24 echo "Downloading the artifact. This could take time..."
25 wget -q -O $ODL_ZIP $NETVIRT_ARTIFACT_URL
26 if [[ $? -ne 0 ]]; then
27     echo "The artifact does not exist! Probably removed due to ODL Jenkins artifact retention policy."
28     echo "Rerun netvirt-patch-test-current-carbon to get artifact rebuilt."
29     exit 1
30 fi
31
32 #TODO(trozet) remove this once odl-pipeline accepts zip files
33 echo "Converting artifact zip to tar.gz"
34 UNZIPPED_DIR=`dirname $(unzip -qql ${ODL_ZIP} | head -n1 | tr -s ' ' | cut -d' ' -f5-)`
35 unzip ${ODL_ZIP}
36 tar czf /tmp/${NETVIRT_ARTIFACT} ${UNZIPPED_DIR}
37
38 echo "Download complete"
39 ls -al /tmp/${NETVIRT_ARTIFACT}