Skip to content

Commit

Permalink
Allow Jenkins to parse the release Jenkinsfile before cancelling non-…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
yrodiere committed Jan 14, 2025
1 parent 1044a0d commit ffecd7d
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions ci/release/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 'Release'
Expand Down Expand Up @@ -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
}

0 comments on commit ffecd7d

Please sign in to comment.