Skip to content

Commit 2e3f5ce

Browse files
authored
Change DOWNSTREAM_BUILD to a regular variable (#428)
Commit 4f5ba02 did not have the entirely intended effect, in that `IS_DOWNSTREAM_BUILD` was set as an environment variable in the style of a declarative pipeline, but this Jenkinsfile is scripted.
1 parent 92b9d52 commit 2e3f5ce

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Jenkinsfile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
/* SPDX-License-Identifier: MIT-0 */
44

5-
environment {
6-
IS_DOWNSTREAM_BUILD = currentBuild.getBuildCauses()[0].class.toString.contains('UpstreamCause')
5+
def is_downstream_build = false
6+
def current_build_causes = currentBuild.getBuildCauses()
7+
for (cause in current_build_causes) {
8+
if (cause._class.toString().contains('UpstreamCause')) {
9+
is_downstream_build = true
10+
}
711
}
812

913
def props = []
@@ -14,7 +18,7 @@ props << parameters([
1418
'Defaults to <code>master</code>.'),
1519
])
1620

17-
if (env.BRANCH_NAME == 'main' && !env.IS_DOWNSTREAM_BUILD) {
21+
if (env.BRANCH_NAME == 'main' && !is_downstream_build) {
1822
def triggers = []
1923
triggers << cron('H H(7-8) * * *')
2024
props << pipelineTriggers(triggers)
@@ -46,7 +50,7 @@ for (example in examples) {
4650
}
4751
}
4852
} catch (e) {
49-
if (env.BRANCH_NAME == 'main' && !env.IS_DOWNSTREAM_BUILD) {
53+
if (env.BRANCH_NAME == 'main' && !is_downstream_build) {
5054
emailext (
5155
subject: "Build failed in Jenkins: ${env.JOB_NAME} #${env.BUILD_NUMBER}",
5256
body: "See <${env.BUILD_URL}display/redirect?page=changes>",

0 commit comments

Comments
 (0)