Skip to content

Commit ffecd7d

Browse files
committed
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.
1 parent 1044a0d commit ffecd7d

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

ci/release/Jenkinsfile

+33-26
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,6 @@ def RELEASE_ON_SCHEDULE = true // Set to `true` *only* on branches where you wan
2222
print "INFO: env.PROJECT = ${env.PROJECT}"
2323
print "INFO: env.JIRA_KEY = ${env.JIRA_KEY}"
2424

25-
// --------------------------------------------
26-
// Build conditions
27-
28-
// Avoid running the pipeline on branch indexing
29-
if (currentBuild.getBuildCauses().toString().contains('BranchIndexingCause')) {
30-
print "INFO: Build skipped due to trigger being Branch Indexing"
31-
currentBuild.result = 'NOT_BUILT'
32-
return
33-
}
34-
35-
def manualRelease = currentBuild.getBuildCauses().toString().contains( 'UserIdCause' )
36-
def cronRelease = currentBuild.getBuildCauses().toString().contains( 'TimerTriggerCause' )
37-
38-
// Only do automatic release on branches where we opted in
39-
if ( !manualRelease && !cronRelease ) {
40-
print "INFO: Build skipped because automated releases on push are disabled on this branch."
41-
currentBuild.result = 'NOT_BUILT'
42-
return
43-
}
44-
45-
if ( !manualRelease && cronRelease && !RELEASE_ON_SCHEDULE ) {
46-
print "INFO: Build skipped because automated releases are disabled on this branch. See constant RELEASE_ON_SCHEDULE in ci/release/Jenkinsfile"
47-
currentBuild.result = 'NOT_BUILT'
48-
return
49-
}
50-
5125
// --------------------------------------------
5226
// Reusable methods
5327

@@ -62,6 +36,9 @@ def checkoutReleaseScripts() {
6236
// --------------------------------------------
6337
// Pipeline
6438

39+
// NOTE: this job checks pre-conditions
40+
// and may cancel itself before even running,
41+
// see "Build conditions" at the bottom of this file.
6542
pipeline {
6643
agent {
6744
label 'Release'
@@ -275,3 +252,33 @@ pipeline {
275252
}
276253
}
277254
}
255+
256+
// --------------------------------------------
257+
// Build conditions
258+
259+
// Note this code is at the end of the file for a reason:
260+
// this code gets executed after Jenkins parses the Jenkinsfile (so that Jenkins knows about the build's parameters/options)
261+
// but before Jenkins runs the build (so that we can cancel it before an agent is even started).
262+
263+
// Avoid running the pipeline on branch indexing
264+
if (currentBuild.getBuildCauses().toString().contains('BranchIndexingCause')) {
265+
print "INFO: Build skipped due to trigger being Branch Indexing"
266+
currentBuild.result = 'NOT_BUILT'
267+
return
268+
}
269+
270+
def manualRelease = currentBuild.getBuildCauses().toString().contains( 'UserIdCause' )
271+
def cronRelease = currentBuild.getBuildCauses().toString().contains( 'TimerTriggerCause' )
272+
273+
// Only do automatic release on branches where we opted in
274+
if ( !manualRelease && !cronRelease ) {
275+
print "INFO: Build skipped because automated releases on push are disabled on this branch."
276+
currentBuild.result = 'NOT_BUILT'
277+
return
278+
}
279+
280+
if ( !manualRelease && cronRelease && !RELEASE_ON_SCHEDULE ) {
281+
print "INFO: Build skipped because automated releases are disabled on this branch. See constant RELEASE_ON_SCHEDULE in ci/release/Jenkinsfile"
282+
currentBuild.result = 'NOT_BUILT'
283+
return
284+
}

0 commit comments

Comments
 (0)