Skip to content

Commit 8d0c591

Browse files
committed
CI: Cancel previous builds
Signed-off-by: Alexey Rivkin <arivkin@nvidia.com>
1 parent fff820b commit 8d0c591

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

.ci/jenkins/Jenkinsfile.github

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/usr/bin/groovy
22

3+
/**
4+
* Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2026. ALL RIGHTS RESERVED.
5+
* See file LICENSE for terms.
6+
*/
7+
38
@Library('blossom-github-lib@master')
49
@Library('github.com/Mellanox/ci-demo@master')
510
def matrix = new com.mellanox.cicd.Matrix()
@@ -8,8 +13,28 @@ import ipp.blossom.*
813

914
def githubHelper = null
1015
def blueOceanUrl = ""
16+
def currentPrNumber = null
1117

1218
if (params.githubData) {
19+
def slurper = new groovy.json.JsonSlurper()
20+
currentPrNumber = slurper.parseText(params.githubData)?.pr?.toString()
21+
22+
// Abort previous running builds of the same PR
23+
if (currentPrNumber) {
24+
try {
25+
Jenkins.instance.getItemByFullName(env.JOB_NAME).builds.findAll {
26+
it.isBuilding() && it.number < currentBuild.number
27+
}.each { b ->
28+
def gd = b.getAction(hudson.model.ParametersAction)?.getParameters()?.find { it.name == 'githubData' }?.value
29+
if (gd && slurper.parseText(gd)?.pr?.toString() == currentPrNumber) {
30+
echo "Aborting build #${b.number} for same PR #${currentPrNumber}"
31+
b.doStop()
32+
}
33+
}
34+
} catch (Exception e) {
35+
echo "Could not abort previous builds: ${e.message}"
36+
}
37+
}
1338
withCredentials([usernamePassword(credentialsId: 'github-token', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
1439
githubHelper = GithubHelper.getInstance("${GIT_PASSWORD}", params.githubData)
1540
}

.ci/jenkins/proj_jjb_github.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) NVIDIA CORPORATION & AFFILIATES, 2026. ALL RIGHTS RESERVED.
2+
# See file LICENSE for terms.
3+
#
14
# Jenkins Job Builder (JJB) configuration for UCX GitHub (Blossom) jobs
25
#
36
# Entry point: ucx-dispatcher-github (generic-webhook-trigger token must match job name)

0 commit comments

Comments
 (0)