终止长时间运行的构建记录 发表于 2019-11-23 | 阅读次数: 12345678910111213141516171819def timeThreshold = 200 // secondsdef jobs = Jenkins.instance.getAllItems(hudson.model.Job.class)jobs.each { job -> def builds = job.getBuilds() if(builds) { builds.each { if(it.isBuilding()) { def duration = System.currentTimeMillis() - it.getStartTimeInMillis() if (duration > timeThreshold * 1000) { println("abort job:${job.name} buildNum:${it.number} duration:${duration}ms") it.getExecutor().interrupt(hudson.model.Result.ABORTED) } } } } else { println("${job.name} don't have builder, skip...") }} 打赏 微信支付