Created
December 25, 2017 12:22
-
-
Save or-shachar/1389336af59ab81272633b2cec05c54d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jenkinsci.plugins.workflow.job.WorkflowRun | |
import org.jenkinsci.plugins.workflow.support.steps.StageStepExecution | |
projectFullName = 'folder/job-name' | |
dryRun = false | |
if(!(projectFullName in String)) { | |
throw new Exception('PARAMETER ERROR: projectFullName must be a string.') | |
} | |
Jenkins.instance.getItemByFullName(projectFullName).builds.each { Run item -> | |
if(item.isBuilding()) { | |
if(item in WorkflowRun) { | |
WorkflowRun run = (WorkflowRun) item | |
if(!dryRun) { | |
//hard kill | |
run.doKill() | |
//release pipeline concurrency locks | |
StageStepExecution.exit(run) | |
} | |
println "Killed ${run}" | |
} else if(item in FreeStyleBuild) { | |
FreeStyleBuild run = (FreeStyleBuild) item | |
if(!dryRun) { | |
run.executor.interrupt(Result.ABORTED) | |
} | |
println "Killed ${run}" | |
} else { | |
println "WARNING: Don't know how to handle ${item.class}" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment