Jenkins - abort running build if new one is started
<p>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 current branch if new one appears in same branch. </p>

<p>For example: I commit and push to branch <code>feature1</code>. Then <code>BUILD_1</code> started in Jenkins. I make another commit and push to branch <code>feature1</code> while <code>BUILD_1</code> is still running. I want <code>BUILD_1</code> to be aborted and to start <code>BUILD_2</code>. </p>

<p>I tried to use <code>stage concurrency=x</code> option, and <a href="https://jenkins.io/blog/2016/10/16/stage-lock-milestone/" rel="noreferrer">stage-lock-milestone</a> feature, but didn't manage to solve my problem.</p>

<p>Also I've read this thread <a href="https://stackoverflow.com/questions/10280846/stopping-jenkins-job-in-case-newer-one-is-started">Stopping Jenkins job in case newer one is started</a>, but there is no solution for my problem.</p>

<p>Do you know any solution to this?</p>