詹金斯 - 中止运行生成,如果新的启动 [英] Jenkins - abort running build if new one is started
问题描述
通过push git仓库触发新的构建。我想要的是在当前分支中中止正在运行的构建,如果新分支出现在同一分支中。
例如:我提交并推送到 feature1
。然后在Jenkins开始 BUILD_1
>。我做了另一个提交并推送到分支 feature1
,同时 BUILD_1
仍在运行。我希望 BUILD_1
被中止并启动 BUILD_2
。
我尝试使用 stage concurrency = x
选项, stage-lock-milestone 功能,但并未解决我的问题。
我也读过这个主题停止Jenkins的工作,以防万一开始,但没有解决我的问题。
你知道这个解决方案吗? 使用 并且在被打断的工作中会有一个日志: 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. For example: I commit and push to branch I tried to use Also I've read this thread Stopping Jenkins job in case newer one is started, but there is no solution for my problem. Do you know any solution to this?
enable job parallel run for your project with use and in the interrupted job there will be a log:
这篇关于詹金斯 - 中止运行生成,如果新的启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
使用为您的项目启用作业并行运行(必要时执行并发构建)$ c>
$ b 执行系统groovy脚本
作为第一个构建步骤: import hudson.model.Result
import jenkins.model.CauseOfInterruption
// iterate通过当前项目运行
build.getProject()._ getRu纳秒()各{ID,游程>。
def exec = run.getExecutor()
//如果运行不是当前版本,并且执行器(正在运行),则停止它
if(run!= build&& (){
//准备中断原因
def cause = new CauseOfInterruption(){
public String getShortDescription(){
returnbuild by build#$ {build.getId()}
}
}
exec.interrupt(Result.ABORTED,cause)
}
}
生成被中止
被生成#12打断
完成:ABORTED
feature1
. Then BUILD_1
started in Jenkins. I make another commit and push to branch feature1
while BUILD_1
is still running. I want BUILD_1
to be aborted and to start BUILD_2
. stage concurrency=x
option, and stage-lock-milestone feature, but didn't manage to solve my problem.Execute concurrent builds if necessary
execute system groovy script
as a first build step:import hudson.model.Result
import jenkins.model.CauseOfInterruption
//iterate through current project runs
build.getProject()._getRuns().each{id,run->
def exec = run.getExecutor()
//if the run is not a current build and it has executor (running) then stop it
if( run!=build && exec!=null ){
//prepare the cause of interruption
def cause = new CauseOfInterruption(){
public String getShortDescription(){
return "interrupted by build #${build.getId()}"
}
}
exec.interrupt(Result.ABORTED, cause)
}
}
Build was aborted
interrupted by build #12
Finished: ABORTED