From 22fd9fd23cf69dfa58d1de775ca0fda23ee38263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Mon, 6 Jan 2025 11:31:02 +0100 Subject: [PATCH] Allow Jenkins to parse the release Jenkinsfile before cancelling non-release triggers This way, we can update parameters/options and have Jenkins take them into account for the next build upon branch indexing or push, even though we don't release on branch indexing or push. --- ci/release/Jenkinsfile | 59 +++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/ci/release/Jenkinsfile b/ci/release/Jenkinsfile index 198166d9479f..31437ea18202 100644 --- a/ci/release/Jenkinsfile +++ b/ci/release/Jenkinsfile @@ -22,32 +22,6 @@ def RELEASE_ON_SCHEDULE = true // Set to `true` *only* on branches where you wan print "INFO: env.PROJECT = ${env.PROJECT}" print "INFO: env.JIRA_KEY = ${env.JIRA_KEY}" -// -------------------------------------------- -// Build conditions - -// Avoid running the pipeline on branch indexing -if (currentBuild.getBuildCauses().toString().contains('BranchIndexingCause')) { - print "INFO: Build skipped due to trigger being Branch Indexing" - currentBuild.result = 'NOT_BUILT' - return -} - -def manualRelease = currentBuild.getBuildCauses().toString().contains( 'UserIdCause' ) -def cronRelease = currentBuild.getBuildCauses().toString().contains( 'TimerTriggerCause' ) - -// Only do automatic release on branches where we opted in -if ( !manualRelease && !cronRelease ) { - print "INFO: Build skipped because automated releases on push are disabled on this branch." - currentBuild.result = 'NOT_BUILT' - return -} - -if ( !manualRelease && cronRelease && !RELEASE_ON_SCHEDULE ) { - print "INFO: Build skipped because automated releases are disabled on this branch. See constant RELEASE_ON_SCHEDULE in ci/release/Jenkinsfile" - currentBuild.result = 'NOT_BUILT' - return -} - // -------------------------------------------- // Reusable methods @@ -62,6 +36,9 @@ def checkoutReleaseScripts() { // -------------------------------------------- // Pipeline +// NOTE: this job checks pre-conditions +// and may cancel itself before even running, +// see "Build conditions" at the bottom of this file. pipeline { agent { label 'Worker&&Containers' @@ -275,3 +252,33 @@ pipeline { } } } + +// -------------------------------------------- +// Build conditions + +// Note this code is at the end of the file for a reason: +// this code gets executed after Jenkins parses the Jenkinsfile (so that Jenkins knows about the build's parameters/options) +// but before Jenkins runs the build (so that we can cancel it before an agent is even started). + +// Avoid running the pipeline on branch indexing +if (currentBuild.getBuildCauses().toString().contains('BranchIndexingCause')) { + print "INFO: Build skipped due to trigger being Branch Indexing" + currentBuild.result = 'NOT_BUILT' + return +} + +def manualRelease = currentBuild.getBuildCauses().toString().contains( 'UserIdCause' ) +def cronRelease = currentBuild.getBuildCauses().toString().contains( 'TimerTriggerCause' ) + +// Only do automatic release on branches where we opted in +if ( !manualRelease && !cronRelease ) { + print "INFO: Build skipped because automated releases on push are disabled on this branch." + currentBuild.result = 'NOT_BUILT' + return +} + +if ( !manualRelease && cronRelease && !RELEASE_ON_SCHEDULE ) { + print "INFO: Build skipped because automated releases are disabled on this branch. See constant RELEASE_ON_SCHEDULE in ci/release/Jenkinsfile" + currentBuild.result = 'NOT_BUILT' + return +}