I use Jenkins and Multibranch Pipeline. I have a job for each active git branch. New build is triggered by push in git repository. What I want is to abort running builds in
Is there a way to abort the build just from one given branch and allow other builds from a different branch to run at the same job. For example, let's say I have Branch1 and Branch2 running in a job. I want to be able to abort all currently executing build from Branch1 except the latest one, at the same time Branch2 starts executing a build and I want Branch2 to be able to execute their build since it's a different branch. Is it possible?
To clarify; We have many branches so we cannot just prevent concurrent builds, cancel the last as soon as the next starts, etc. Whatever method is used must specifically check if the branch already has a job running for it, not if the job, in general, is already running. Running the code is execute system groovy in Jenkins.
import hudson.model.Result
import jenkins.model.CauseOfInterruption
import groovy.transform.Field
import jenkins.model.*
build.getProject()._getRuns().iterator().each{ run ->
def exec = run.getExecutor()
//from each run get the branch_name and put it into the list, add it to the list
def branchName = build.environment.get("GIT_BRANCH")
def list = []
list.add(branchName)
for (i = 0; i