Add Jerma in blacklist logics
[releng.git] / jjb / 3rd_party_ci / download-netvirt-artifact.sh
index be2d405..ac7f76c 100755 (executable)
@@ -1,27 +1,38 @@
 #!/bin/bash
 #!/bin/bash
-set -e
+set -o errexit
+set -o nounset
+set -o pipefail
 
 
-if [ -z ${WORKSPACE} ]; then
-  echo "WORKSPACE is unset. Please do so."
-  exit 1
+echo "Attempting to fetch the artifact location from ODL Jenkins"
+if [ "$ODL_BRANCH" != 'master' ]; then
+  DIST=$(echo ${ODL_BRANCH} | sed -rn 's#([a-zA-Z]+)/([a-zA-Z]+)#\2#p')
+  ODL_BRANCH=$(echo ${ODL_BRANCH} | sed -rn 's#([a-zA-Z]+)/([a-zA-Z]+)#\1%2F\2#p')
+else
+  DIST='neon'
 fi
 fi
-# wipe the WORKSPACE
-/bin/rm -rf $WORKSPACE/*
 
 
-echo "Attempting to fetch the artifact location from ODL Jenkins"
-CHANGE_DETAILS_URL="https://git.opendaylight.org/gerrit/changes/netvirt~master~$GERRIT_CHANGE_ID/detail"
+echo "ODL Distribution is ${DIST}"
+ODL_ZIP="karaf-SNAPSHOT.zip"
+CHANGE_DETAILS_URL="https://git.opendaylight.org/gerrit/changes/${GERRIT_PROJECT}~${ODL_BRANCH}~${GERRIT_CHANGE_ID}/detail"
 # due to limitation with the Jenkins Gerrit Trigger, we need to use Gerrit REST API to get the change details
 # due to limitation with the Jenkins Gerrit Trigger, we need to use Gerrit REST API to get the change details
-ODL_JOB_URL=$(curl -s $CHANGE_DETAILS_URL | grep netvirt-patch-test-current-carbon | tail -1 | \
-    sed 's/\\n//g' | awk '{print $6}')
-NETVIRT_ARTIFACT_URL="${ODL_JOB_URL}org.opendaylight.integration\$distribution-karaf/artifact/org.opendaylight.integration/distribution-karaf/0.6.0-SNAPSHOT/distribution-karaf-0.6.0-SNAPSHOT.tar.gz"
+ODL_BUILD_JOB_NUM=$(curl --fail ${CHANGE_DETAILS_URL} | grep -Eo "${GERRIT_PROJECT}-distribution-check-${DIST}/[0-9]+" | tail -1 | grep -Eo [0-9]+)
+DISTRO_CHECK_CONSOLE_LOG="https://logs.opendaylight.org/releng/vex-yul-odl-jenkins-1/${GERRIT_PROJECT}-distribution-check-${DIST}/${ODL_BUILD_JOB_NUM}/console.log.gz"
+NETVIRT_ARTIFACT_URL=$(curl --fail --compressed ${DISTRO_CHECK_CONSOLE_LOG} | grep 'BUNDLE_URL' | cut -d = -f 2)
+
 echo -e "URL to artifact is\n\t$NETVIRT_ARTIFACT_URL"
 
 echo "Downloading the artifact. This could take time..."
 echo -e "URL to artifact is\n\t$NETVIRT_ARTIFACT_URL"
 
 echo "Downloading the artifact. This could take time..."
-wget -q -O $NETVIRT_ARTIFACT $NETVIRT_ARTIFACT_URL
-if [[ $? -ne 0 ]]; then
+if ! wget -q -O $ODL_ZIP $NETVIRT_ARTIFACT_URL; then
     echo "The artifact does not exist! Probably removed due to ODL Jenkins artifact retention policy."
     echo "The artifact does not exist! Probably removed due to ODL Jenkins artifact retention policy."
-    echo "Rerun netvirt-patch-test-current-carbon to get artifact rebuilt."
+    echo "Use 'recheck' on the gerrit to get artifact rebuilt."
     exit 1
 fi
     exit 1
 fi
+
+#TODO(trozet) remove this once odl-pipeline accepts zip files
+echo "Converting artifact zip to tar.gz"
+UNZIPPED_DIR=`dirname $(unzip -qql ${ODL_ZIP} | head -n1 | tr -s ' ' | cut -d' ' -f5-)`
+unzip ${ODL_ZIP}
+tar czf /tmp/${NETVIRT_ARTIFACT} ${UNZIPPED_DIR}
+
 echo "Download complete"
 echo "Download complete"
-ls -al $NETVIRT_ARTIFACT
+ls -al /tmp/${NETVIRT_ARTIFACT}