jenkins-gerrit: fix ambiguous use of review api

Fix an error when the same Change-Id is used on multiple branches or in
theory projects. This is actually allowed by gerrit, and we use this
e.g. when backporting patches from master.

Use the project, change number (e.g. 30147) and patchset number (e.g. 2)
instead of the Change-Id.

Fix for:
  + ssh -p 29418 -l jenkins gerrit.osmocom.org gerrit review 4835a62cd88f0d69db76fb3bfd2df02176a91a6d --json
  fatal: "4835a62cd88f0d69db76fb3bfd2df02176a91a6d" matches multiple patch sets

Related: https://gerrit-review.googlesource.com/Documentation/cmd-review.html
Change-Id: I2d627f8f3b400fa57a50a228d47df2194f60fd08
This commit is contained in:
Oliver Smith 2022-11-14 14:35:58 +01:00 committed by osmith
parent 6b7741400d
commit f560ce08ab
5 changed files with 28 additions and 2 deletions

View File

@ -30,6 +30,15 @@
description: | description: |
osmo-ci.git branch osmo-ci.git branch
default: 'master' default: 'master'
- string:
name: GERRIT_PROJECT
description: set by gerrit verification pipeline job
- string:
name: GERRIT_CHANGE_NUMBER
description: set by gerrit verification pipeline job
- string:
name: GERRIT_PATCHSET_NUMBER
description: set by gerrit verification pipeline job
- string: - string:
name: GERRIT_BRANCH name: GERRIT_BRANCH
description: set by gerrit verification pipeline job description: set by gerrit verification pipeline job

View File

@ -28,6 +28,15 @@
description: | description: |
osmo-ci.git branch osmo-ci.git branch
default: 'master' default: 'master'
- string:
name: GERRIT_PROJECT
description: set by gerrit verification pipeline job
- string:
name: GERRIT_CHANGE_NUMBER
description: set by gerrit verification pipeline job
- string:
name: GERRIT_PATCHSET_NUMBER
description: set by gerrit verification pipeline job
- string: - string:
name: GERRIT_BRANCH name: GERRIT_BRANCH
description: set by gerrit verification pipeline job description: set by gerrit verification pipeline job

View File

@ -445,6 +445,9 @@
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {{ catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {{
env.PIPELINE_LINT_PASSED = "0" env.PIPELINE_LINT_PASSED = "0"
build job: 'gerrit-lint', parameters: [ build job: 'gerrit-lint', parameters: [
string(name: "GERRIT_PROJECT", value: "${{env.GERRIT_PROJECT}}"),
string(name: "GERRIT_CHANGE_NUMBER", value: "${{env.GERRIT_CHANGE_NUMBER}}"),
string(name: "GERRIT_PATCHSET_NUMBER", value: "${{env.GERRIT_PATCHSET_NUMBER}}"),
string(name: "GERRIT_BRANCH", value: "${{env.GERRIT_BRANCH}}"), string(name: "GERRIT_BRANCH", value: "${{env.GERRIT_BRANCH}}"),
string(name: "GERRIT_HOST", value: "${{env.GERRIT_HOST}}"), string(name: "GERRIT_HOST", value: "${{env.GERRIT_HOST}}"),
string(name: "GERRIT_PATCHSET_REVISION", value: "${{env.GERRIT_PATCHSET_REVISION}}"), string(name: "GERRIT_PATCHSET_REVISION", value: "${{env.GERRIT_PATCHSET_REVISION}}"),
@ -510,6 +513,9 @@
// comment + vote to gerrit // comment + vote to gerrit
script {{ script {{
build job: 'gerrit-pipeline-result', parameters: [ build job: 'gerrit-pipeline-result', parameters: [
string(name: "GERRIT_PROJECT", value: "${{env.GERRIT_PROJECT}}"),
string(name: "GERRIT_CHANGE_NUMBER", value: "${{env.GERRIT_CHANGE_NUMBER}}"),
string(name: "GERRIT_PATCHSET_NUMBER", value: "${{env.GERRIT_PATCHSET_NUMBER}}"),
string(name: "GERRIT_BRANCH", value: "${{env.GERRIT_BRANCH}}"), string(name: "GERRIT_BRANCH", value: "${{env.GERRIT_BRANCH}}"),
string(name: "GERRIT_HOST", value: "${{env.GERRIT_HOST}}"), string(name: "GERRIT_HOST", value: "${{env.GERRIT_HOST}}"),
string(name: "GERRIT_PATCHSET_REVISION", value: "${{env.GERRIT_PATCHSET_REVISION}}"), string(name: "GERRIT_PATCHSET_REVISION", value: "${{env.GERRIT_PATCHSET_REVISION}}"),

View File

@ -68,7 +68,8 @@ if [ "$ERROR" = 1 ]; then
"$GERRIT_HOST" \ "$GERRIT_HOST" \
gerrit \ gerrit \
review \ review \
"$GERRIT_PATCHSET_REVISION" \ --project "$GERRIT_PROJECT" \
"$GERRIT_CHANGE_NUMBER,$GERRIT_PATCHSET_NUMBER" \
--json \ --json \
< gerrit_report.json < gerrit_report.json
fi fi

View File

@ -26,6 +26,7 @@ ssh \
"$GERRIT_HOST" \ "$GERRIT_HOST" \
gerrit \ gerrit \
review \ review \
"$GERRIT_PATCHSET_REVISION" \ --project "$GERRIT_PROJECT" \
"$GERRIT_CHANGE_NUMBER,$GERRIT_PATCHSET_NUMBER" \
--json \ --json \
< gerrit_report.json < gerrit_report.json