Allow merge request updates to cancel running builds from the same source branch#1901
Merged
krisstern merged 9 commits intoJun 17, 2026
Conversation
…ning job that was triggered by the same merge request
275945c to
1c058f1
Compare
The handler cancels both queued and running MR builds, so the old name was misleading. Also remove the redundant nine-parameter factory overload that always defaulted cancelRunningBuildsOnUpdate to false.
bd3872d to
06d6bec
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in feature to abort currently running Jenkins builds when a GitLab merge request is updated, scoped to builds originating from the same source project ID and source branch. It extends the existing “cancel pending builds on update” behavior by also supporting in-flight build cancellation and updates UI/help/docs accordingly.
Changes:
- Introduces
cancelRunningBuildsOnUpdatetrigger option and wiring from config → handler. - Renames/generalizes the pending-build cancellation helper to
MergeRequestBuildHandlerand adds running-build cancellation logic. - Adds/updates documentation and tests for the new behavior.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/MergeRequestBuildHandler.java |
Adds logic to abort running builds matching MR source project/branch and introduces a new interruption cause. |
src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/merge/MergeRequestHookTriggerHandlerImpl.java |
Wires the new “cancel running builds on update” flag into MR update handling. |
src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/merge/MergeRequestHookTriggerHandlerFactory.java |
Extends factory configuration to include the new flag (and updates config builder). |
src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/AbstractWebHookTriggerHandler.java |
Switches from the old pending-build handler to the renamed MR build handler. |
src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/push/OpenMergeRequestPushHookTriggerHandler.java |
Updates call sites to use the renamed handler’s resolvePendingBuildName. |
src/main/java/com/dabsquared/gitlabjenkins/MergeRequestTriggerConfig.java |
Adds a default config method for the new flag. |
src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java |
Adds persisted field + getter/setter for cancelRunningBuildsOnUpdate. |
src/main/resources/com/dabsquared/gitlabjenkins/GitLabPushTrigger/config.jelly |
Adds UI checkbox for “Cancel running merge request builds on update”. |
src/main/resources/com/dabsquared/gitlabjenkins/GitLabPushTrigger/help-cancelRunningBuildsOnUpdate.html |
Adds help text for the new checkbox. |
src/test/java/com/dabsquared/gitlabjenkins/trigger/handler/MergeRequestBuildHandlerTest.java |
Adds a unit test for running-build cancellation behavior. |
README.md |
Documents the new configuration option and behavior. |
Comments suppressed due to low confidence (3)
src/test/java/com/dabsquared/gitlabjenkins/trigger/handler/MergeRequestBuildHandlerTest.java:186
otherBranchExecis never attached to theotherBranchrun (you passnullas the executor), so theverify(otherBranchExec, never())...assertion is vacuous and won't catch accidental aborts. Pass the executor intorunningBuildWithCause(...)so an incorrect abort would fail the test.
src/test/java/com/dabsquared/gitlabjenkins/trigger/handler/MergeRequestBuildHandlerTest.java:190otherProjectExecis never attached to theotherProjectrun (you passnullas the executor), so theverify(otherProjectExec, never())...assertion is vacuous and won't catch accidental aborts. Pass the executor intorunningBuildWithCause(...)so an incorrect abort would fail the test.
src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/MergeRequestBuildHandler.java:74stopBuild(...)returns early whenbuild.getExecutor()isnull, butcancelRunningBuilds(...)still updates the GitLab commit status tocanceled. This can leave the build running in Jenkins while reporting it as canceled in GitLab. Only update the commit status if the build was actually interrupted (or otherwise successfully stopped).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Testing done
Submitter checklist