Jenkins - abort running build if new one is started

前端 未结 9 2516
失恋的感觉
失恋的感觉 2020-12-04 15:51

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

9条回答
  •  盖世英雄少女心
    2020-12-04 16:19

    Adding to Brandon Squizzato's answer. If builds are sometimes skipped the milestone mechanism as mentioned will fail. Setting older milestones in a for-loop solves this.

    Also make sure you don't have disableConcurrentBuilds in your options. Otherwise the pipeline doesn't get to the milestone step and this won't work.

    def buildNumber = env.BUILD_NUMBER as int
    for (int i = 1; i < buildNumber; i++)
    {
        milestone(i)
    }
    milestone(buildNumber)
    

提交回复
热议问题