From ac2c053519c92203f66a617e997afbc9b1ad773a Mon Sep 17 00:00:00 2001 From: Pewxz <124064710+pewxz@users.noreply.github.com> Date: Mon, 18 Sep 2023 18:04:43 +0200 Subject: [PATCH] Added new stagfe to check and cancel old job (#215) New stage has been added to check if there is a old build from the same job running If yes, it cancel the old one and keep the new one running Co-authored-by: Ben --- Jenkinsfile | 55 ++++++++++++++++------------------------------------- 1 file changed, 16 insertions(+), 39 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ae2e57a0..46e14e7f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,34 +18,24 @@ pipeline { LATEST_BRANCH="main" } stages { + stage('Check and Cancel Old Builds') { + steps { + script { + def currentBuildNumber = currentBuild.number + + // Check all build from same project + for (build in currentBuild.rawBuild.getParent().getBuilds()) { + // Check if an older build is still running and cancel it in favor of the new one + if (build.number < currentBuildNumber && build.building) { + echo "Cancelling build ${build.number}" + build.doStop() + } + } + } + } + } stage('build and push') { parallel { - // stage('build and push amd64_epyc2 image') { - // agent { - // label 'amd64_epyc2' - // } - // environment { - // ARCH="amd64_epyc2" - // } - // steps { - // script { - // myBuildandPush.buildAndPush() - // } - // } - // } - // stage('build and push amd64_epyc3 image') { - // agent { - // label 'amd64_epyc3' - // } - // environment { - // ARCH="amd64_epyc3" - // } - // steps { - // script { - // myBuildandPush.buildAndPush() - // } - // } - // } stage('Build and push arm64_graviton2 image') { agent { label 'arm64_graviton2' @@ -59,19 +49,6 @@ pipeline { } } } - // stage('Build and push intel_xeon3 image') { - // agent { - // label 'intel_xeon3' - // } - // environment { - // ARCH="intel_xeon3" - // } - // steps { - // script { - // myBuildandPush.buildAndPush() - // } - // } - // } } } stage('push latest') {