Merge "remove unused policy jobs"
[infra/cicd.git] / jjb / onap / push-upstream-jobs.sh
index 67b7f246b42c9d97a60a37c9b2878f2469ccf420..c4fcfe682691e1d8ea49ac429125173bb768682f 100755 (executable)
@@ -31,6 +31,7 @@ set -euxo pipefail
 cd "$WORKSPACE"
 
 onap_gerrit_base='gerrit.onap.org:29418'
+nordix_gerrit_rest='https://gerrit.nordix.org'
 echo >&2 "Collecting information about what and how to push towards ONAP"
 
 # The git hash of the commit in the review this job runs on
@@ -71,3 +72,15 @@ push_result=${PIPESTATUS[0]}
 if [ $push_result -ne 0 ]; then
     grep '(no new changes)' push_result.txt
 fi
+
+# When a push-upstream job completes successfully.
+# The link to the corresponding upstream gerrit review is posted
+# on the Nordix gerrit using Gerrit API and infra user HTTP API Key.
+if grep -q http push_result.txt; then
+    URL=$(sed -ne 's/.*\(http\S*\).*/\1/p' < push_result.txt)
+    echo "URL: $URL"
+    curl --request 'POST' -H 'Content-Type:application/json' \
+     "${nordix_gerrit_rest}/a/changes/${GERRIT_CHANGE_NUMBER}/revisions/${GERRIT_PATCHSET_NUMBER}/review" \
+     --user "${GERRIT_USER}:${GERRIT_API_KEY}" \
+     --data "{\"message\": \"UPSTRAM URL: ${URL}\"}"
+fi