importhudson.model.Resultimportjenkins.model.CauseOfInterruption//iterate through current project runsbuild.getProject()._getRuns().each { id, run ->def exec = run.getExecutor()//if the run is not a current build and it has executor (running) then stop itif( run!=build && exec!=null ) {//prepare the cause of interruptiondef cause =newCauseOfInterruption() {publicStringgetShortDescription() {return"interrupted by build #${build.getId()}" } } exec.interrupt( Result.ABORTED, cause ) }}//just for test do something long...Thread.sleep(10000)
Signals an error. Useful if you want to conditionally abort some part of your program. You can also just throw new Exception(), but this step will avoid printing a stack trace
Prints a message to the log and sets the overall build result and the stage result to UNSTABLE. The message will also be associated with the stage result and may be shown in visualizations.
importorg.jenkinsci.plugins.workflow.graph.FlowGraphWalkerimportorg.jenkinsci.plugins.workflow.graph.FlowNodetry {// just for demo, a success step and a failure step node { sh 'true' sh 'false' }} finally {FlowGraphWalker walker =newFlowGraphWalker(currentBuild.rawBuild.getExecution())for (FlowNode flowNode: walker) {// do whatever you want with flowNode echo flowNode.dump() }}