From 7fb84b6f28b5bda33fb93960d471ba36bbf55ffa Mon Sep 17 00:00:00 2001 From: Jose Granha Date: Mon, 12 Feb 2024 15:27:08 +0000 Subject: [PATCH] JENKINS-72649: Add project parameter to SSH commands Add --project to the SSH review command calls so that it is possible to distinguish between conflicting change numbers within distinct projects. This change is backwards compatible to earlier versions of Gerrit, but becomes relevant both from optimization reasons since 2.15 and to prevent change collisions from 3.5 with the support for imported projects. Bug: Issue JENKINS-72649 Release-Notes: Add project parameter to SSH commands --- .../plugins/gerrit/trigger/config/Config.java | 18 ++++--- .../gerrit/trigger/GerritServer/index.jelly | 12 ++--- .../gerrit/trigger/config/ConfigTest.java | 54 ++++++++++--------- .../trigger/spec/VoteSameTopicTest.java | 8 +-- .../hudson/plugins/gerrit/trigger/casc.yaml | 12 ++--- .../gerrit-trigger.xml | 8 +-- .../gerrit-trigger.xml | 8 +-- 7 files changed, 64 insertions(+), 56 deletions(-) diff --git a/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/config/Config.java b/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/config/Config.java index 11e77adbf..926b2eb6a 100644 --- a/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/config/Config.java +++ b/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/config/Config.java @@ -334,27 +334,33 @@ public void setValues(JSONObject formData) { gerritVerifiedCmdBuildStarted = formData.optString( "gerritVerifiedCmdBuildStarted", - "gerrit review , --message 'Build Started ' " + "gerrit review --project , " + + "--message 'Build Started ' " + "--verified --code-review --tag " + Constants.TAG_VALUE); gerritVerifiedCmdBuildFailed = formData.optString( "gerritVerifiedCmdBuildFailed", - "gerrit review , --message 'Build Failed ' " + "gerrit review --project , " + + "--message 'Build Failed ' " + "--verified --code-review --tag " + Constants.TAG_VALUE); gerritVerifiedCmdBuildSuccessful = formData.optString( "gerritVerifiedCmdBuildSuccessful", - "gerrit review , --message 'Build Successful ' " + "gerrit review --project , " + + "--message 'Build Successful ' " + "--verified --code-review --tag " + Constants.TAG_VALUE); gerritVerifiedCmdBuildUnstable = formData.optString( "gerritVerifiedCmdBuildUnstable", - "gerrit review , --message 'Build Unstable ' " + "gerrit review --project , " + + "--message 'Build Unstable ' " + "--verified --code-review --tag " + Constants.TAG_VALUE); gerritVerifiedCmdBuildNotBuilt = formData.optString( "gerritVerifiedCmdBuildNotBuilt", - "gerrit review , --message 'No Builds Executed ' " + "gerrit review --project , " + + "--message 'No Builds Executed ' " + "--verified --code-review --tag " + Constants.TAG_VALUE); gerritVerifiedCmdBuildAborted = formData.optString( "gerritVerifiedCmdBuildAborted", - "gerrit review , --message 'Build Aborted ' " + "gerrit review --project , " + + "--message 'Build Aborted ' " + "--verified --code-review --tag " + Constants.TAG_VALUE); gerritFrontEndUrl = formData.optString( "gerritFrontEndUrl", diff --git a/src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritServer/index.jelly b/src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritServer/index.jelly index d7886fef1..cc14f1ec1 100644 --- a/src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritServer/index.jelly +++ b/src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritServer/index.jelly @@ -217,37 +217,37 @@ help="/plugin/gerrit-trigger/help-GerritVerifiedCmdBuildStarted.html"> + default="gerrit review --project <GERRIT_NAME> <CHANGE>,<PATCHSET> --message 'Build Started <BUILDURL> <STARTED_STATS>' --verified <VERIFIED> --code-review <CODE_REVIEW>"/> + default="gerrit review --project <GERRIT_NAME> <CHANGE>,<PATCHSET> --message 'Build Successful <BUILDS_STATS>' --verified <VERIFIED> --code-review <CODE_REVIEW>"/> + default="gerrit review --project <GERRIT_NAME> <CHANGE>,<PATCHSET> --message 'Build Failed <BUILDS_STATS>' --verified <VERIFIED> --code-review <CODE_REVIEW>"/> + default="gerrit review --project <GERRIT_NAME> <CHANGE>,<PATCHSET> --message 'Build Unstable <BUILDS_STATS>' --verified <VERIFIED> --code-review <CODE_REVIEW>"/> + default="gerrit review --project <GERRIT_NAME> <CHANGE>,<PATCHSET> --message 'No Builds Executed <BUILDS_STATS>' --verified <VERIFIED> --code-review <CODE_REVIEW>"/> + default="gerrit review --project <GERRIT_NAME> <CHANGE>,<PATCHSET> --message 'Build Aborted <BUILDS_STATS>' --verified <VERIFIED> --code-review <CODE_REVIEW>"/> diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/config/ConfigTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/config/ConfigTest.java index 3df68c5d6..ce0d65517 100644 --- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/config/ConfigTest.java +++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/config/ConfigTest.java @@ -63,17 +63,18 @@ public class ConfigTest { */ @Test public void testSetValues() { - String formString = "{\"gerritVerifiedCmdBuildFailed\":\"gerrit review , " + String formString = "{\"gerritVerifiedCmdBuildFailed\":" + + "\"gerrit review --project , " + "--message 'Failed misserably ' --verified --code-review \"," - + "\"gerritVerifiedCmdBuildStarted\":\"gerrit review , " + + "\"gerritVerifiedCmdBuildStarted\":\"gerrit review --project , " + "--message 'Started yay!! ' --verified --code-review \"," - + "\"gerritVerifiedCmdBuildSuccessful\":\"gerrit review ," + + "\"gerritVerifiedCmdBuildSuccessful\":\"gerrit review --project ," + " --message 'Successful wonderful ' --verified --code-review \"," - + "\"gerritVerifiedCmdBuildUnstable\":\"gerrit review , " + + "\"gerritVerifiedCmdBuildUnstable\":\"gerrit review --project , " + "--message 'Unstable and you are to ' --verified --code-review \"," - + "\"gerritVerifiedCmdBuildNotBuilt\":\"gerrit review , " + + "\"gerritVerifiedCmdBuildNotBuilt\":\"gerrit review --project , " + "--message 'You are not built for it ' --verified --code-review \"," - + "\"gerritVerifiedCmdBuildAborted\":\"gerrit review , " + + "\"gerritVerifiedCmdBuildAborted\":\"gerrit review --project , " + "--message 'Aborted oupsy ' --verified --code-review \"," + "\"gerritAuthKeyFile\":\"/home/local/gerrit/.ssh/id_rsa\"," + "\"gerritAuthKeyFilePassword\":\"passis\"," @@ -100,24 +101,24 @@ public void testSetValues() { + "\"notificationLevel\":\"OWNER\"}"; JSONObject form = (JSONObject)JSONSerializer.toJSON(formString); Config config = new Config(form); - assertEquals("gerrit review , " + assertEquals("gerrit review --project , " + "--message 'Failed misserably ' --verified --code-review ", config.getGerritCmdBuildFailed()); - assertEquals("gerrit review , " + assertEquals("gerrit review --project , " + "--message 'Started yay!! ' --verified --code-review ", config.getGerritCmdBuildStarted()); - assertEquals("gerrit review ," + assertEquals("gerrit review --project ," + " --message 'Successful wonderful ' --verified --code-review ", config.getGerritCmdBuildSuccessful()); - assertEquals("gerrit review , " + assertEquals("gerrit review --project , " + "--message 'Unstable and you are to ' --verified --code-review ", config.getGerritCmdBuildUnstable()); - assertEquals("gerrit review , " + assertEquals("gerrit review --project , " + "--message 'You are not built for it ' --verified --code-review ", config.getGerritCmdBuildNotBuilt()); - assertEquals("gerrit review , " - + "--message 'Aborted oupsy ' --verified --code-review ", - config.getGerritCmdBuildAborted()); + assertEquals("gerrit review --project , " + + "--message 'Aborted oupsy ' --verified --code-review ", + config.getGerritCmdBuildAborted()); assertEquals(new File("/home/local/gerrit/.ssh/id_rsa").getPath(), config.getGerritAuthKeyFile().getPath()); assertEquals("passis", config.getGerritAuthKeyFilePassword()); @@ -167,17 +168,18 @@ public void testProjectListRefreshIntervalZeroValue() { */ @Test public void testCopyConfig() { - String formString = "{\"gerritVerifiedCmdBuildFailed\":\"gerrit review , " + String formString = "{\"gerritVerifiedCmdBuildFailed\":" + + "\"gerrit review --project , " + "--message 'Failed misserably ' --verified --code-review \"," - + "\"gerritVerifiedCmdBuildStarted\":\"gerrit review , " + + "\"gerritVerifiedCmdBuildStarted\":\"gerrit review --project , " + "--message 'Started yay!! ' --verified --code-review \"," - + "\"gerritVerifiedCmdBuildSuccessful\":\"gerrit review ," + + "\"gerritVerifiedCmdBuildSuccessful\":\"gerrit review --project ," + " --message 'Successful wonderful ' --verified --code-review \"," - + "\"gerritVerifiedCmdBuildUnstable\":\"gerrit review , " + + "\"gerritVerifiedCmdBuildUnstable\":\"gerrit review --project , " + "--message 'Unstable and you are to ' --verified --code-review \"," - + "\"gerritVerifiedCmdBuildNotBuilt\":\"gerrit review , " + + "\"gerritVerifiedCmdBuildNotBuilt\":\"gerrit review --project , " + "--message 'You are not built for it ' --verified --code-review \"," - + "\"gerritVerifiedCmdBuildAborted\":\"gerrit review , " + + "\"gerritVerifiedCmdBuildAborted\":\"gerrit review --project , " + "--message 'Aborted oupsy ' --verified --code-review \"," + "\"gerritAuthKeyFile\":\"/home/local/gerrit/.ssh/id_rsa\"," + "\"gerritAuthKeyFilePassword\":\"passis\"," @@ -205,22 +207,22 @@ public void testCopyConfig() { JSONObject form = (JSONObject)JSONSerializer.toJSON(formString); Config initialConfig = new Config(form); Config config = new Config(initialConfig); - assertEquals("gerrit review , " + assertEquals("gerrit review --project , " + "--message 'Failed misserably ' --verified --code-review ", config.getGerritCmdBuildFailed()); - assertEquals("gerrit review , " + assertEquals("gerrit review --project , " + "--message 'Started yay!! ' --verified --code-review ", config.getGerritCmdBuildStarted()); - assertEquals("gerrit review ," + assertEquals("gerrit review --project ," + " --message 'Successful wonderful ' --verified --code-review ", config.getGerritCmdBuildSuccessful()); - assertEquals("gerrit review , " + assertEquals("gerrit review --project , " + "--message 'Unstable and you are to ' --verified --code-review ", config.getGerritCmdBuildUnstable()); - assertEquals("gerrit review , " + assertEquals("gerrit review --project , " + "--message 'You are not built for it ' --verified --code-review ", config.getGerritCmdBuildNotBuilt()); - assertEquals("gerrit review , " + assertEquals("gerrit review --project , " + "--message 'Aborted oupsy ' --verified --code-review ", config.getGerritCmdBuildAborted()); assertEquals(new File("/home/local/gerrit/.ssh/id_rsa").getPath(), diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/VoteSameTopicTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/VoteSameTopicTest.java index ff8e25a69..d60e15bef 100644 --- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/VoteSameTopicTest.java +++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/VoteSameTopicTest.java @@ -165,10 +165,10 @@ public void testVoteSameTopic() throws Exception { //CS IGNORE MagicNumber FOR NEXT 4 LINES. REASON: Testdata. server.waitForCommand("gerrit stream-events", 2000); triggerAndWait(projects[0]); - checkCommand("gerrit review 100,1 --message 'Build Started[\\s\\S.]*"); - checkCommand("gerrit review 101,1 --message 'Build Started[\\s\\S.]*"); - checkCommand("gerrit review 100,1 --message 'Build Successful[\\s\\S.]*"); - checkCommand("gerrit review 101,1 --message 'Build Successful[\\s\\S.]*"); + checkCommand("gerrit review --project " + projects[0] + " 100,1 --message 'Build Started[\\s\\S.]*"); + checkCommand("gerrit review --project " + projects[1] + " 101,1 --message 'Build Started[\\s\\S.]*"); + checkCommand("gerrit review --project " + projects[0] + " 100,1 --message 'Build Successful[\\s\\S.]*"); + checkCommand("gerrit review --project " + projects[1] + " 101,1 --message 'Build Successful[\\s\\S.]*"); } /** diff --git a/src/test/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/casc.yaml b/src/test/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/casc.yaml index c1ecc0ce1..ba6c72f50 100644 --- a/src/test/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/casc.yaml +++ b/src/test/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/casc.yaml @@ -38,12 +38,12 @@ unclassified: gerritBuildNotBuiltCodeReviewValue: 4 gerritBuildAbortedCodeReviewValue: 4 - gerritCmdBuildStarted: "gerrit review , --message 'Build Started CMD ' --verified --code-review --tag autogenerated:jenkins-gerrit-trigger" - gerritCmdBuildSuccessful: "gerrit review , --message 'Build Successful CMD ' --verified --code-review --tag autogenerated:jenkins-gerrit-trigger" - gerritCmdBuildFailed: "gerrit review , --message 'Build Failed CMD ' --verified --code-review --tag autogenerated:jenkins-gerrit-trigger" - gerritCmdBuildUnstable: "gerrit review , --message 'Build Unstable CMD ' --verified --code-review --tag autogenerated:jenkins-gerrit-trigger" - gerritCmdBuildNotBuilt: "gerrit review , --message 'No Builds Executed CMD ' --verified --code-review --tag autogenerated:jenkins-gerrit-trigger" - gerritCmdBuildAborted: "gerrit review , --message 'Build Aborted CMD ' --verified --code-review --tag autogenerated:jenkins-gerrit-trigger" + gerritCmdBuildStarted: "gerrit review --project , --message 'Build Started CMD ' --verified --code-review --tag autogenerated:jenkins-gerrit-trigger" + gerritCmdBuildSuccessful: "gerrit review --project , --message 'Build Successful CMD ' --verified --code-review --tag autogenerated:jenkins-gerrit-trigger" + gerritCmdBuildFailed: "gerrit review --project , --message 'Build Failed CMD ' --verified --code-review --tag autogenerated:jenkins-gerrit-trigger" + gerritCmdBuildUnstable: "gerrit review --project , --message 'Build Unstable CMD ' --verified --code-review --tag autogenerated:jenkins-gerrit-trigger" + gerritCmdBuildNotBuilt: "gerrit review --project , --message 'No Builds Executed CMD ' --verified --code-review --tag autogenerated:jenkins-gerrit-trigger" + gerritCmdBuildAborted: "gerrit review --project , --message 'Build Aborted CMD ' --verified --code-review --tag autogenerated:jenkins-gerrit-trigger" buildScheduleDelay: 4 dynamicConfigRefreshInterval: 31 diff --git a/src/test/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/extensions/GerritTriggeredBuildListenerTest/gerrit-trigger.xml b/src/test/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/extensions/GerritTriggeredBuildListenerTest/gerrit-trigger.xml index f18080d03..7717a6352 100644 --- a/src/test/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/extensions/GerritTriggeredBuildListenerTest/gerrit-trigger.xml +++ b/src/test/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/extensions/GerritTriggeredBuildListenerTest/gerrit-trigger.xml @@ -7,10 +7,10 @@ /tmp/jenkins-testkey 3 - gerrit review --message 'Build Successful <BUILDS_STATS>' --label Verified=<VERIFIED> --label Code-Review=<CODE_REVIEW> <CHANGE>,<PATCHSET> - gerrit review --message 'Build Unstable <BUILDS_STATS>' --label Verified=<VERIFIED> --label Code-Review=<CODE_REVIEW> <CHANGE>,<PATCHSET> - gerrit review --message 'Build Failed <BUILDS_STATS>' --label Verified=<VERIFIED> --label Code-Review=<CODE_REVIEW> <CHANGE>,<PATCHSET> - gerrit review --message 'Build Started <BUILDURL> <STARTED_STATS>' --label Verified=<VERIFIED> --label Code-Review=<CODE_REVIEW> <CHANGE>,<PATCHSET> + gerrit review --project <GERRIT_NAME> --message 'Build Successful <BUILDS_STATS>' --label Verified=<VERIFIED> --label Code-Review=<CODE_REVIEW> <CHANGE>,<PATCHSET> + gerrit review --project <GERRIT_NAME> --message 'Build Unstable <BUILDS_STATS>' --label Verified=<VERIFIED> --label Code-Review=<CODE_REVIEW> <CHANGE>,<PATCHSET> + gerrit review --project <GERRIT_NAME> --message 'Build Failed <BUILDS_STATS>' --label Verified=<VERIFIED> --label Code-Review=<CODE_REVIEW> <CHANGE>,<PATCHSET> + gerrit review --project <GERRIT_NAME> --message 'Build Started <BUILDURL> <STARTED_STATS>' --label Verified=<VERIFIED> --label Code-Review=<CODE_REVIEW> <CHANGE>,<PATCHSET> http://localhost/ 0 0 diff --git a/src/test/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/DuplicateGerritListenersHudsonTestCase/gerrit-trigger.xml b/src/test/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/DuplicateGerritListenersHudsonTestCase/gerrit-trigger.xml index 17a954da9..c0817650f 100644 --- a/src/test/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/DuplicateGerritListenersHudsonTestCase/gerrit-trigger.xml +++ b/src/test/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/DuplicateGerritListenersHudsonTestCase/gerrit-trigger.xml @@ -7,10 +7,10 @@ /tmp/jenkins-testkey 3 - gerrit review <CHANGE>,<PATCHSET> --message 'Build Successful <BUILDS_STATS>' --verified <VERIFIED> --code-review <CODE_REVIEW> - gerrit review <CHANGE>,<PATCHSET> --message 'Build Unstable <BUILDS_STATS>' --verified <VERIFIED> --code-review <CODE_REVIEW> - gerrit review <CHANGE>,<PATCHSET> --message 'Build Failed <BUILDS_STATS>' --verified <VERIFIED> --code-review <CODE_REVIEW> - gerrit review <CHANGE>,<PATCHSET> --message 'Build Started <BUILDURL> <STARTED_STATS>' --verified <VERIFIED> --code-review <CODE_REVIEW> + gerrit review --project <GERRIT_NAME> <CHANGE>,<PATCHSET> --message 'Build Successful <BUILDS_STATS>' --verified <VERIFIED> --code-review <CODE_REVIEW> + gerrit review --project <GERRIT_NAME> <CHANGE>,<PATCHSET> --message 'Build Unstable <BUILDS_STATS>' --verified <VERIFIED> --code-review <CODE_REVIEW> + gerrit review --project <GERRIT_NAME> <CHANGE>,<PATCHSET> --message 'Build Failed <BUILDS_STATS>' --verified <VERIFIED> --code-review <CODE_REVIEW> + gerrit review --project <GERRIT_NAME> <CHANGE>,<PATCHSET> --message 'Build Started <BUILDURL> <STARTED_STATS>' --verified <VERIFIED> --code-review <CODE_REVIEW> http://localhost/ 0 0