@@ -22,32 +22,6 @@ def RELEASE_ON_SCHEDULE = false // Set to `true` *only* on branches where you wa
2222print " INFO: env.PROJECT = ${ env.PROJECT} "
2323print " 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
@@ -63,6 +37,9 @@ def checkoutReleaseScripts() {
6337// --------------------------------------------
6438// Pipeline
6539
40+ // NOTE: this job checks pre-conditions
41+ // and may cancel itself before even running,
42+ // see "Build conditions" at the bottom of this file.
6643pipeline {
6744 agent {
6845 label ' Worker&&Containers'
@@ -285,3 +262,33 @@ pipeline {
285262 }
286263 }
287264}
265+
266+ // --------------------------------------------
267+ // Build conditions
268+
269+ // Note this code is at the end of the file for a reason:
270+ // this code gets executed after Jenkins parses the Jenkinsfile (so that Jenkins knows about the build's parameters/options)
271+ // but before Jenkins runs the build (so that we can cancel it before an agent is even started).
272+
273+ // Avoid running the pipeline on branch indexing
274+ if (currentBuild. getBuildCauses(). toString(). contains(' BranchIndexingCause' )) {
275+ print " INFO: Build skipped due to trigger being Branch Indexing"
276+ currentBuild. result = ' NOT_BUILT'
277+ return
278+ }
279+
280+ def manualRelease = currentBuild. getBuildCauses(). toString(). contains( ' UserIdCause' )
281+ def cronRelease = currentBuild. getBuildCauses(). toString(). contains( ' TimerTriggerCause' )
282+
283+ // Only do automatic release on branches where we opted in
284+ if ( ! manualRelease && ! cronRelease ) {
285+ print " INFO: Build skipped because automated releases on push are disabled on this branch."
286+ currentBuild. result = ' NOT_BUILT'
287+ return
288+ }
289+
290+ if ( ! manualRelease && cronRelease && ! RELEASE_ON_SCHEDULE ) {
291+ print " INFO: Build skipped because automated releases are disabled on this branch. See constant RELEASE_ON_SCHEDULE in ci/release/Jenkinsfile"
292+ currentBuild. result = ' NOT_BUILT'
293+ return
294+ }
0 commit comments