diff --git a/payload/src/main/java/io/jenkins/jenkinsfile/runner/Runner.java b/payload/src/main/java/io/jenkins/jenkinsfile/runner/Runner.java index 952a1ec4..cc77f238 100644 --- a/payload/src/main/java/io/jenkins/jenkinsfile/runner/Runner.java +++ b/payload/src/main/java/io/jenkins/jenkinsfile/runner/Runner.java @@ -3,9 +3,11 @@ import com.cloudbees.hudson.plugins.folder.Folder; import com.cloudbees.plugins.credentials.Credentials; import com.cloudbees.plugins.credentials.CredentialsUnavailableException; +import hudson.init.Terminator; import hudson.model.Action; import hudson.model.Cause; import hudson.model.CauseAction; +import hudson.model.Executor; import hudson.model.Failure; import hudson.model.ParametersAction; import hudson.model.StringParameterValue; @@ -176,4 +178,17 @@ private void writeLogTo(PrintStream out) throws IOException, InterruptedExceptio } } } + + @Terminator + public static void stopBuilds() throws Exception { + for (WorkflowJob p : Jenkins.get().allItems(WorkflowJob.class)) { + for (WorkflowRun b : p.getBuilds()) { + Executor exec = b.getExecutor(); + if (exec != null) { + exec.interrupt(); + } + } + } + } + }