-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d07eca1
commit f93fc56
Showing
1 changed file
with
3 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,3 @@ | ||
pipeline { | ||
agent any | ||
|
||
stages { | ||
stage('Abort previous running builds') { | ||
steps { | ||
abortPreviousRunningBuilds() | ||
} | ||
} | ||
|
||
stage('Build') { | ||
steps { | ||
sleep(5) | ||
} | ||
} | ||
|
||
stage('Test') { | ||
steps { | ||
sleep(5) | ||
} | ||
} | ||
} | ||
} | ||
|
||
def abortPreviousRunningBuilds() { | ||
def previousBuild = currentBuild.getRawBuild().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 CauseOfInterruption.UserInterruption("Aborted by newer build #${currentBuild.number}")) | ||
} | ||
} | ||
previousBuild = previousBuild.getPreviousBuildInProgress() | ||
} | ||
} | ||
def buildNumber = env.BUILD_NUMBER as int | ||
if (buildNumber > 1) milestone(buildNumber - 1) | ||
milestone(buildNumber) |