Dej*_*ges 8 jenkins jenkins-plugins
如果在作业(A)被多次触发的情况下,是否可以指定先前的作业从队列中删除,并且只有最新的作业留在队列中或者如果有足够的空闲插槽则启动?
提前致谢!
使用execute system groovy script步骤:
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)
}
}
//just for test do something long...
Thread.sleep(10000)
Run Code Online (Sandbox Code Playgroud)
并且在中断的工作中会有一个日志:
Build was aborted
interrupted by build #12
Finished: ABORTED
Run Code Online (Sandbox Code Playgroud)
您可以使用通过Groovy Script Plugin运行的系统 Groovy 脚本来完成此操作。这样的脚本可以通过其编程 API直接访问 Jenkins 。我没有看到任何其他方式。
| 归档时间: |
|
| 查看次数: |
6571 次 |
| 最近记录: |