Autocancel branch builds on pull request builds will ensure running source branch builds are aborted when a new pull request build starts.
This could happen when a branch is pushed and immediately filed as a pull request, where branch build becomes redundant.
To match pull requests, the plugin leverages env.CHANGE_BRANCH
, which should be set to the matching source branch name.
Then, the plugin looks for branch jobs named as the source branch name under multibranch pipeline parent job to abort any running builds.
If env.CHANGE_BRANCH
is not defined, the step will do nothing.
autocancelBranchBuildsOnPullRequestBuilds()
node {
// Steps
}