From 7ffccabd0f86dde3b2c5a46497ac2103d7678733 Mon Sep 17 00:00:00 2001 From: Radoslaw Wicik Date: Thu, 6 May 2021 15:53:39 +0200 Subject: [PATCH] [EGD-6670] Cancel jenkins build on PR update Stop previous builds. --- Jenkinsfile | 50 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index db3d4810726038c91d10eef3acfe4e536d28aebe..b2e88e178789b76397f68777796224ddc610dfb0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,3 +1,20 @@ +def cancelPreviousBuilds() { + + def jobName = env.JOB_NAME + def buildNumber = env.BUILD_NUMBER.toInteger() + def currentJob = Jenkins.instance.getItemByFullName(jobName) + + for (def build : currentJob.builds) { + def exec = build.getExecutor() + + /* Kill older jobs */ + if (build.isBuilding() && build.number.toInteger() < buildNumber && exec != null) { + def cause = { "Job stoped by #${buildNumber}" as String} as CauseOfInterruption + exec.interrupt(Result.ABORTED, cause) + println("Aborting previous build:#${build.number}") + } + } +} pipeline { agent { node { @@ -6,9 +23,16 @@ pipeline { } environment { - JOBS=5 + JOBS=10 } stages { + stage('Check for previous running builds') { + steps { + script { + cancelPreviousBuilds() + } + } + } stage('Initial checks') { environment { @@ -73,16 +97,15 @@ ccache --show-stats''' } } + environment { + PATH="/usr/local/cmake-3.19.5-Linux-x86_64/bin:/usr/local/gcc-arm-none-eabi-10-2020-q4-major/bin:$PATH" + CCACHE_DIR="/ccache/Linux" + } + steps { echo "Build" sh '''#!/bin/bash -e -PATH="/usr/local/cmake-3.19.5-Linux-x86_64/bin:/usr/local/gcc-arm-none-eabi-10-2020-q4-major/bin:$PATH" -export JOBS=${JOBS:-6} -export CCACHE_DIR=/ccache/Linux - echo "JOBS=${JOBS}" -echo "\'workspace dir:${WORKSPACE}\'" - pushd "${WORKSPACE}" echo "./configure.sh linux Debug -G Ninja" @@ -90,6 +113,11 @@ echo "./configure.sh linux Debug -G Ninja" pushd build-linux-Debug ninja -j ${JOBS} +popd''' + echo "Build Unit Tests" + sh '''#!/bin/bash -e +pushd "${WORKSPACE}" +pushd build-linux-Debug ninja -j ${JOBS} unittests popd popd''' @@ -104,12 +132,8 @@ pushd "${WORKSPACE}" popd''' echo "Run Unit Tests" sh '''#!/bin/bash -e -PATH="/usr/local/cmake-3.19.5-Linux-x86_64/bin:/usr/local/gcc-arm-none-eabi-10-2020-q4-major/bin:$PATH" export JOBS=${JOBS:-6} -export CCACHE_DIR=/ccache/Linux echo "JOBS=${JOBS}" -echo "\'workspace dir:${WORKSPACE}\'" - pushd "${WORKSPACE}" ./tools/run_unittests.sh enabled_unittests ./tools/check_unittests.sh @@ -117,10 +141,6 @@ pushd build-linux-Debug ./googletest-gui popd popd''' - echo "CCache stats" - sh '''#!/bin/bash -export CCACHE_DIR=/ccache/Linux -ccache --show-stats''' } } }