blob: 0fb8d9aa6647b75ea94931f49ffd268aee305198 [file] [log] [blame]
Jakub Joseff7283ee2017-03-20 19:10:13 +01001/**
2 * Long running jobs killer
3 *
4 * MAX_DURATION_IN_HOURS - max permitted job duration in hours
5 */
6common = new com.mirantis.mk.Common()
7
8def MAX_ALLOWED_DURATION_IN_SECONDS = 3600 * Interger.parseInt(MAX_DURATION_IN_HOURS)
9
10for (int i=0; i < Jenkins.instance.items.size(); i++) {
11 def job = Jenkins.instance.items[i]
12 def runningBuilds = job.builds.findAll{build -> build.isBuilding()}
13 def jobName = job.name
14 for(int j=0; j < runningBuilds.size(); j++){
15 def build = runningBuilds[j]
16 int durationInSeconds = (System.currentTimeMillis() - build.getTimeInMillis())/1000.0
17 if(durationInSeconds > MAX_ALLOWED_DURATION_IN_SECONDS){
18 common.infoMsg("Aborting ${job.name}-${build.id} takes ${durationInSeconds}s")
19 try{
20 build.finish(hudson.model.Result.ABORTED, new java.io.IOException("Aborting build"));
21 }catch(e){
22 common.errorMsg("Error occured during aborting build: Exception: ${e}")
23 }
24 }
25 }
26}
27
28
29