Access BUILD_CAUSE and BUILD_CAUSE_USERIDCAUSE through Build Flow DSL

561 views
Skip to first unread message

GS_L

unread,
Oct 29, 2015, 9:15:04 AM10/29/15
to Jenkins Users
Hi

To know who triggered a buildflow job  I tried to print the BUILD_CAUSE env variable in the following ways:

1. println "BUILD_CAUSE = $BUILD_CAUSE"
    build failed - error:
  ERROR: Failed to run DSL Script
  groovy.lang.MissingPropertyException: No such property: BUILD_CAUSE for class: Script1

2. println build.properties["environment"]["BUILD_CAUSE"]
    build passed - output is null

What is the right way to get the BUILD_CAUSE in Build Flow job?

Martin d'Anjou

unread,
Oct 29, 2015, 4:15:58 PM10/29/15
to Jenkins Users
Been asking myself the same question for 3 years. The only solution for me is to use EnvInject, fetch the cause from the Jenkins internal objects, and export it as a new env variable to the build. It gets complicated when the cause is another build, you have to do a recursive search to get to the bottom if it, but ultimately it is doable. Start with currentBuild.getCauses() in EnvInject. Or use a System Groovy script as per this stackoverflow answer.

GS_L

unread,
Nov 1, 2015, 7:21:02 AM11/1/15
to Jenkins Users
The problem is that the EnvInject isn't enabled through the BuildFlow.

Stefan Thomasson

unread,
Nov 2, 2015, 4:46:37 AM11/2/15
to jenkins...@googlegroups.com
Hi,

Doesn't this work?

build.environment["BUILD_CAUSE"]

Atleast this works for me for manually started builds. However it will not get the real cause if it is started by upstream jobs
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/3856d186-97f4-4548-9eed-ddc7fbaf55a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stefan Thomasson

unread,
Nov 2, 2015, 4:15:56 PM11/2/15
to jenkins...@googlegroups.com
Hi,
And as always with buildflow, make sure that the "use workspace" is enabled in the job configuration.
Since the environment variable seem to be created by envinject plugin.

//stefan


1 nov 2015 kl. 13:21 skrev GS_L <limor...@gmail.com>:

--
Reply all
Reply to author
Forward
0 new messages