-if [[ $retVal -eq 0 ]]
-then
- git remote rm upstream
- git remote add upstream "ssh://$username@review.opendev.org:29418/$project.git"
-else
- git remote add upstream "ssh://$username@review.opendev.org:29418/$project.git"
-fi
+# Nordix Gerrit can map the email address of the user pushed the change to
+# the review to the Gerrit username of the accound in Nordix Gerrit. This
+# should match with the Gerrit username in the OpenDev Gerrit.
+# TODO(gibi): parse the json propely if there are tools (e.g. jq) available on
+# the jenkins slave
+username=$(
+ curl -s -H 'Accept: application/json' \
+ "$nordix_gerrit_rest/accounts/?q=email:$GERRIT_EVENT_ACCOUNT_EMAIL&o=DETAILS" \
+ | tee /dev/stderr \
+ | sed -n 's/^.*"username":"\(\S*\)".*$/\1/p')
+
+opendev_remote_url="ssh://$username@$opendev_gerrit_base/$opendev_project"
+
+# GERRIT_BRANCH is the _intended_ branch of the commit under review
+# E.g. git push HEAD:refs/for/master => GERRIT_BRANCH='master'
+# GERRIT_TOPIC is the rest of the refspec after GERRIT_BRANCH
+refspec="$commit_hash:refs/for/$GERRIT_BRANCH/$GERRIT_TOPIC"
+
+echo >&2 "Pushing to OpenDev"
+
+# do not fail if git push fails as in case of no new changes we want to succeed. See below.
+set +o pipefail