Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-11409

Gerrit-trigger should support waiting for downstream jobs of triggered builds

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      When using gerrit-trigger to trigger a build from Gerrit, gerrit-trigger should have support for waiting for downstream jobs to complete (and take those into considerations).

      The use case is to have a build job followed by a test job (if the build completes), but currently gerrit-trigger will report success as soon as the build job finishes.

      The work-around is to create a wrapper job that uses parameterized trigger to start a "blocking" build of the build job, followed by a "blocking" build of the test job. The downside of this is that the wrapper occupies a slot on an executor, even though it just blocks, and that the output in gerrit doesn't clearly indicate if building or testing failed.

        Attachments

          Activity

          Hide
          yannack yannack bbbb added a comment -

          The problem with the parametrized-plugin-blocking-buildstep solution is also that you cannot copy artifacts, as artifact copying is only possible in the post build. This means that all the features around artifacts are lost (md5s, etc).
          The solution mentioned by Kohsuke, item #2 specifically, with UpstreamCause, would unfortunately not work for me, as the Upstream cause of the build does not pass through buildFlow.

          I believe one of the challenges here is what to do if the job / promotion you are waiting for never triggers ? For example, if you have some build which fails, it may not trigger downstream, and the "end" job might not happen. This means there will probably have to be a way to manually terminate the gerrit operation in case what is expected doesn't happen. Otherwise, you may end up with a lot of "open" gerrit events, waiting for jobs which may well never be triggered.

          One option I have been thinking of would be to have in the post-build phase, an action:
          'fail/approve the triggering Gerrit event with ID: ', and allow a parameter. You would have to pass the Gerrit-event ID via build parameters for instance, but parameters are very well supported. This is sufficiently flexible for most use-cases I believe. optionally, we could even imagine:

          • the fail/approve is directly related to the outcome of the build phase (have an option for "stable build only"). Failure => fail gerrit, Success => OK Gerrit, Unstable => OK Gerrit
          • the fail/approve is manually set (to use is more complex constructs, such as promotions, etc).
          Show
          yannack yannack bbbb added a comment - The problem with the parametrized-plugin-blocking-buildstep solution is also that you cannot copy artifacts, as artifact copying is only possible in the post build. This means that all the features around artifacts are lost (md5s, etc). The solution mentioned by Kohsuke, item #2 specifically, with UpstreamCause, would unfortunately not work for me, as the Upstream cause of the build does not pass through buildFlow. I believe one of the challenges here is what to do if the job / promotion you are waiting for never triggers ? For example, if you have some build which fails, it may not trigger downstream, and the "end" job might not happen. This means there will probably have to be a way to manually terminate the gerrit operation in case what is expected doesn't happen. Otherwise, you may end up with a lot of "open" gerrit events, waiting for jobs which may well never be triggered. One option I have been thinking of would be to have in the post-build phase, an action: 'fail/approve the triggering Gerrit event with ID: ', and allow a parameter. You would have to pass the Gerrit-event ID via build parameters for instance, but parameters are very well supported. This is sufficiently flexible for most use-cases I believe. optionally, we could even imagine: the fail/approve is directly related to the outcome of the build phase (have an option for "stable build only"). Failure => fail gerrit, Success => OK Gerrit, Unstable => OK Gerrit the fail/approve is manually set (to use is more complex constructs, such as promotions, etc).
          Hide
          yannack yannack bbbb added a comment -

          OK, I have just submitted a pull request adding this feature. I hope it makes it into the plugin soon. It works by adding a "delayed approval" setting to the Gerrit Trigger. When this is selected, the triggered job no longer auto-submits its result. Instead, there is a post-build action available which the downstream job will have to run. It needs to have a job name and a build number as a parameter, so these will need to be passed on as build variables.
          So as to solve the above problem of waiting forever, the "flexible publish" plugin can be used. Set it so you only do the delayed approval on your upstream project if it fails (thus not triggering downstream). In the most downstream project you can set it to always do the delayed approval.
          As you see this is still pretty manual, but it is a first draft, and has the benefit of working If there is enough interest, it can always be improved on later

          Show
          yannack yannack bbbb added a comment - OK, I have just submitted a pull request adding this feature. I hope it makes it into the plugin soon. It works by adding a "delayed approval" setting to the Gerrit Trigger. When this is selected, the triggered job no longer auto-submits its result. Instead, there is a post-build action available which the downstream job will have to run. It needs to have a job name and a build number as a parameter, so these will need to be passed on as build variables. So as to solve the above problem of waiting forever, the "flexible publish" plugin can be used. Set it so you only do the delayed approval on your upstream project if it fails (thus not triggering downstream). In the most downstream project you can set it to always do the delayed approval. As you see this is still pretty manual, but it is a first draft, and has the benefit of working If there is enough interest, it can always be improved on later
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Yannack
          Path:
          gerrithudsontrigger/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ToGerritRunListener.java
          gerrithudsontrigger/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritDelayedApprover.java
          gerrithudsontrigger/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger.java
          gerrithudsontrigger/src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritDelayedApprover/config.jelly
          gerrithudsontrigger/src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger/config.jelly
          gerrithudsontrigger/src/main/webapp/trigger/help-DelayedApproval.html
          gerrithudsontrigger/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerTest.java
          gerrithudsontrigger/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/DuplicatesUtil.java
          gerrithudsontrigger/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/Setup.java
          http://jenkins-ci.org/commit/gerrit-trigger-plugin/5f672f2db13314377c9db239bdb6ae4491136345
          Log:
          Delayed approval mechanism [FIXED JENKINS-11409]

          This patch introduces the possibility for a delayed approval to be sent
          back to Gerrit. This is a relatively advanced use case, so the setting
          has been placed in the Advanced section for the Trigger settings.
          When one selects "delayed approval", the completion of the build will
          NOT send an approval back to Gerrit. Instead, the triggering event stays
          open, and needs to be closed later on. This can be done by using the new
          post-build action "Send a Gerrit delayed approval". At the moment, this
          notifier expects to read the name of the job and build number from build
          variables. If these point to an existing build which has a Gerrit event
          as a trigger, which has not been submitted due to "delayed approval",
          then that approval will be sent. In particular, this allows to modify
          the status of that build through other job (e.g., using Groovy scripts),
          and mark it UNSTABLE (e.g., if a subsequent build were to fail), which
          is a way one can change the result of the Approval in Gerrit.

          Amends: fixed broken style and broken unit tests

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Yannack Path: gerrithudsontrigger/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ToGerritRunListener.java gerrithudsontrigger/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritDelayedApprover.java gerrithudsontrigger/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger.java gerrithudsontrigger/src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritDelayedApprover/config.jelly gerrithudsontrigger/src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger/config.jelly gerrithudsontrigger/src/main/webapp/trigger/help-DelayedApproval.html gerrithudsontrigger/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerTest.java gerrithudsontrigger/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/DuplicatesUtil.java gerrithudsontrigger/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/Setup.java http://jenkins-ci.org/commit/gerrit-trigger-plugin/5f672f2db13314377c9db239bdb6ae4491136345 Log: Delayed approval mechanism [FIXED JENKINS-11409] This patch introduces the possibility for a delayed approval to be sent back to Gerrit. This is a relatively advanced use case, so the setting has been placed in the Advanced section for the Trigger settings. When one selects "delayed approval", the completion of the build will NOT send an approval back to Gerrit. Instead, the triggering event stays open, and needs to be closed later on. This can be done by using the new post-build action "Send a Gerrit delayed approval". At the moment, this notifier expects to read the name of the job and build number from build variables. If these point to an existing build which has a Gerrit event as a trigger, which has not been submitted due to "delayed approval", then that approval will be sent. In particular, this allows to modify the status of that build through other job (e.g., using Groovy scripts), and mark it UNSTABLE (e.g., if a subsequent build were to fail), which is a way one can change the result of the Approval in Gerrit. Amends: fixed broken style and broken unit tests
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Robert Sandell
          Path:
          gerrithudsontrigger/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ToGerritRunListener.java
          gerrithudsontrigger/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritDelayedApprover.java
          gerrithudsontrigger/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger.java
          gerrithudsontrigger/src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/Messages.properties
          gerrithudsontrigger/src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritDelayedApprover/config.jelly
          gerrithudsontrigger/src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger/config.jelly
          gerrithudsontrigger/src/main/webapp/trigger/help-DelayedApproval.html
          gerrithudsontrigger/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ToGerritRunListenerTest.java
          gerrithudsontrigger/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerTest.java
          gerrithudsontrigger/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/DuplicatesUtil.java
          gerrithudsontrigger/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/Setup.java
          http://jenkins-ci.org/commit/gerrit-trigger-plugin/c512069db1936d16eb969eab63d85e111188b0e0
          Log:
          Merge pull request #122 from yannack/delayedApprove

          Delayed approval mechanism [FIXED JENKINS-11409]

          Compare: https://github.com/jenkinsci/gerrit-trigger-plugin/compare/3246d8e32d87...c512069db193

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Robert Sandell Path: gerrithudsontrigger/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ToGerritRunListener.java gerrithudsontrigger/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritDelayedApprover.java gerrithudsontrigger/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger.java gerrithudsontrigger/src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/Messages.properties gerrithudsontrigger/src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritDelayedApprover/config.jelly gerrithudsontrigger/src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger/config.jelly gerrithudsontrigger/src/main/webapp/trigger/help-DelayedApproval.html gerrithudsontrigger/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ToGerritRunListenerTest.java gerrithudsontrigger/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerTest.java gerrithudsontrigger/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/DuplicatesUtil.java gerrithudsontrigger/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/Setup.java http://jenkins-ci.org/commit/gerrit-trigger-plugin/c512069db1936d16eb969eab63d85e111188b0e0 Log: Merge pull request #122 from yannack/delayedApprove Delayed approval mechanism [FIXED JENKINS-11409] Compare: https://github.com/jenkinsci/gerrit-trigger-plugin/compare/3246d8e32d87...c512069db193
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Robert Sandell
          Path:
          build-config/swe_checkstyle.xml
          src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ToGerritRunListener.java
          src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritDelayedApprover.java
          src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger.java
          src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritDelayedApprover/config.jelly
          src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger/config.jelly
          src/main/webapp/trigger/help-DelayedApproval.html
          src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ToGerritRunListenerTest.java
          src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerTest.java
          src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/DuplicatesUtil.java
          src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/Setup.java
          http://jenkins-ci.org/commit/gerrit-trigger-plugin/48311691d693d0935030491b0a4ba8277c9e0396
          Log:
          Removed delayed approval feature JENKINS-11409

          It is a bit too risky to have enabled in large installations
          and the dependency feature provides a similar functionality.
          Since delayed approval has so far only been in a beta release
          we can remove it without much consequence.

          Change-Id: I2cf2efc7b1f45be7db3ae69dde6cb8cdc88b405f

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Robert Sandell Path: build-config/swe_checkstyle.xml src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ToGerritRunListener.java src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritDelayedApprover.java src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger.java src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritDelayedApprover/config.jelly src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger/config.jelly src/main/webapp/trigger/help-DelayedApproval.html src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ToGerritRunListenerTest.java src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerTest.java src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/DuplicatesUtil.java src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/Setup.java http://jenkins-ci.org/commit/gerrit-trigger-plugin/48311691d693d0935030491b0a4ba8277c9e0396 Log: Removed delayed approval feature JENKINS-11409 It is a bit too risky to have enabled in large installations and the dependency feature provides a similar functionality. Since delayed approval has so far only been in a beta release we can remove it without much consequence. Change-Id: I2cf2efc7b1f45be7db3ae69dde6cb8cdc88b405f

            People

            • Assignee:
              rsandell rsandell
              Reporter:
              jorgenpt Jørgen Tjernø
            • Votes:
              6 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: