Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import hudson.model.FreeStyleBuild
- import hudson.model.Result
- import hudson.model.Run
- import jenkins.model.Jenkins
- import org.jenkinsci.plugins.workflow.job.WorkflowRun
- import org.jenkinsci.plugins.workflow.support.steps.StageStepExecution
- if(!binding.hasVariable('dryRun')) {
- dryRun = true
- }
- if(!binding.hasVariable('projectFullName')) {
- projectFullName = 'project/full/name'
- }
- //type check user defined parameters/bindings
- if(!(dryRun instanceof Boolean)) {
- throw new Exception('PARAMETER ERROR: dryRun must be a boolean.')
- }
- if(!(projectFullName instanceof String)) {
- throw new Exception('PARAMETER ERROR: projectFullName must be a string.')
- }
- Jenkins.instance.getItemByFullName(projectFullName).builds.each { Run item ->
- if(item.isBuilding()) {
- if(item instanceof WorkflowRun) {
- WorkflowRun run = (WorkflowRun) item
- if(!dryRun) {
- //hard kill
- run.doKill()
- //release pipeline concurrency locks
- StageStepExecution.exit(run)
- }
- println "Killed ${run}"
- } else if(item instanceof 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}"
- }
- }
- }.each{ build ->
- if(build.isBuilding()) {
- build.doKill()
- println "killed ${build}"
- }
- }
- //null so no result shows up
- null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement