Skip to content

Commit

Permalink
abort previous builds (PegaSysEng#817)
Browse files Browse the repository at this point in the history
  • Loading branch information
Errorific authored and tmohay committed Feb 8, 2019
1 parent 9f98d6f commit 16ee776
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env groovy

import hudson.model.Result
import hudson.model.Run
import jenkins.model.CauseOfInterruption.UserInterruption

if (env.BRANCH_NAME == "master") {
properties([
buildDiscarder(
Expand All @@ -21,6 +25,26 @@ if (env.BRANCH_NAME == "master") {
def docker_image = 'docker:18.06.0-ce-dind'
def build_image = 'pegasyseng/pantheon-build:0.0.5-jdk11'

def abortPreviousBuilds() {
Run previousBuild = currentBuild.rawBuild.getPreviousBuildInProgress()

while (previousBuild != null) {
if (previousBuild.isInProgress()) {
def executor = previousBuild.getExecutor()
if (executor != null) {
echo ">> Aborting older build #${previousBuild.number}"
executor.interrupt(Result.ABORTED, new UserInterruption(
"Aborted by newer build #${currentBuild.number}"
))
}
}

previousBuild = previousBuild.getPreviousBuildInProgress()
}
}

abortPreviousBuilds()

try {
parallel UnitTests: {
def stage_name = "Unit tests node: "
Expand Down

0 comments on commit 16ee776

Please sign in to comment.