Skip to content

Allow merge request updates to cancel running builds from the same source branch#1901

Merged
krisstern merged 9 commits into
jenkinsci:masterfrom
manjukion:feature/cancel-running-builds-on-merge-request-update
Jun 17, 2026
Merged

Allow merge request updates to cancel running builds from the same source branch#1901
krisstern merged 9 commits into
jenkinsci:masterfrom
manjukion:feature/cancel-running-builds-on-merge-request-update

Conversation

@manjukion

Copy link
Copy Markdown
Contributor

Testing done

  • Added/updated unit tests in PendinbBuildsHandlerTest
  • Executed 'mvn spotless:apply'
  • Executed 'mvn spotbugs:check'
  • Executed 'mvn clean verify'
  • Executed 'mvn clean package'
  • Generated and installed the plugin HPI in a Jenkins test instance
  • Verified that running builds triggered by the same merge request source branch are cancelled when the merge request is updated
  • Verified the new help documentation renders correctly from the Jenkins job configuration page

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

@manjukion manjukion requested a review from a team as a code owner June 1, 2026 18:05
@github-actions github-actions Bot added documentation Improvements or additions to documentation tests This PR adds/removes/updates test cases labels Jun 1, 2026
@manjukion manjukion force-pushed the feature/cancel-running-builds-on-merge-request-update branch from 275945c to 1c058f1 Compare June 1, 2026 19:48
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.
@manjukion manjukion force-pushed the feature/cancel-running-builds-on-merge-request-update branch from bd3872d to 06d6bec Compare June 1, 2026 20:01
@krisstern krisstern added the enhancement For changelog: Minor enhancement. Use 'major-rfe' for changes to be highlighted label Jun 17, 2026
@krisstern krisstern requested a review from Copilot June 17, 2026 15:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 cancelRunningBuildsOnUpdate trigger option and wiring from config → handler.
  • Renames/generalizes the pending-build cancellation helper to MergeRequestBuildHandler and 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

  • otherBranchExec is never attached to the otherBranch run (you pass null as the executor), so the verify(otherBranchExec, never())... assertion is vacuous and won't catch accidental aborts. Pass the executor into runningBuildWithCause(...) so an incorrect abort would fail the test.
    src/test/java/com/dabsquared/gitlabjenkins/trigger/handler/MergeRequestBuildHandlerTest.java:190
  • otherProjectExec is never attached to the otherProject run (you pass null as the executor), so the verify(otherProjectExec, never())... assertion is vacuous and won't catch accidental aborts. Pass the executor into runningBuildWithCause(...) so an incorrect abort would fail the test.
    src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/MergeRequestBuildHandler.java:74
  • stopBuild(...) returns early when build.getExecutor() is null, but cancelRunningBuilds(...) still updates the GitLab commit status to canceled. 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.

@krisstern krisstern merged commit 7cd63d1 into jenkinsci:master Jun 17, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement For changelog: Minor enhancement. Use 'major-rfe' for changes to be highlighted tests This PR adds/removes/updates test cases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants