ONAP: Post back the Gerrit upstream change URL on push-upstream 21/8221/2
authorrobert.tomczyk <robert.tomczyk@est.tech>
Wed, 31 Mar 2021 15:46:13 +0000 (16:46 +0100)
committerRobert Tomczyk <robert.tomczyk@est.tech>
Wed, 31 Mar 2021 15:52:58 +0000 (15:52 +0000)
The link to the corresponding upstream gerrit review is posted
on the Nordix gerrit patch using Gerrit API and infra user HTTP API Key.

Change-Id: I59aebd77c2d1beaf735a8a624ce58f9b79d00496

jjb/global/jjb-macros.yaml
jjb/onap/global-templates-onap-push-upstream.yaml
jjb/onap/push-upstream-jobs.sh

index d9a37c502a1df8537728cd24371b59d61a78a827..b971341cbbe0d2dae557a0581704dc06c6e28369 100644 (file)
               username: NORDIXINFRA_GITHUB_USERNAME
               password: NORDIXINFRA_GITHUB_TOKEN
 
+# wrappers to use for jobs
+- wrapper:
+    name: nordix-gerrit-http-api-token
+    wrappers:
+      - credentials-binding:
+          - username-password-separated:
+              credential-id: nordixinfra-nordix-gerrit-http-api-token
+              username: GERRIT_USER
+              password: GERRIT_API_KEY
+
 # timeout wrapper to use for jobs
 - wrapper:
     name: build-timeout
index 6977e60a226f92dbec731741cdda8e2fe1b8da5e..c4de3bd3e849a673e092dff0b6a2fbaa7301285c 100644 (file)
@@ -34,6 +34,7 @@
       - ssh-agent-credentials:
           users:
             - 'infra-upstream-gerrit-ssh-passphrase'
+      - nordix-gerrit-http-api-token
 
     builders:
       - shell:
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