From a22a9305fd6e1a948e641a2a73137eadc698de72 Mon Sep 17 00:00:00 2001 From: "robert.tomczyk" Date: Wed, 31 Mar 2021 16:46:13 +0100 Subject: [PATCH] ONAP: Post back the Gerrit upstream change URL on push-upstream 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 | 10 ++++++++++ jjb/onap/global-templates-onap-push-upstream.yaml | 1 + jjb/onap/push-upstream-jobs.sh | 13 +++++++++++++ 3 files changed, 24 insertions(+) diff --git a/jjb/global/jjb-macros.yaml b/jjb/global/jjb-macros.yaml index d9a37c50..b971341c 100644 --- a/jjb/global/jjb-macros.yaml +++ b/jjb/global/jjb-macros.yaml @@ -459,6 +459,16 @@ 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 diff --git a/jjb/onap/global-templates-onap-push-upstream.yaml b/jjb/onap/global-templates-onap-push-upstream.yaml index 6977e60a..c4de3bd3 100644 --- a/jjb/onap/global-templates-onap-push-upstream.yaml +++ b/jjb/onap/global-templates-onap-push-upstream.yaml @@ -34,6 +34,7 @@ - ssh-agent-credentials: users: - 'infra-upstream-gerrit-ssh-passphrase' + - nordix-gerrit-http-api-token builders: - shell: diff --git a/jjb/onap/push-upstream-jobs.sh b/jjb/onap/push-upstream-jobs.sh index 67b7f246..c4fcfe68 100755 --- a/jjb/onap/push-upstream-jobs.sh +++ b/jjb/onap/push-upstream-jobs.sh @@ -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 -- 2.25.1