There is a BUILD_CAUSE environment variable that can have values like: SCMTRIGGER, MANUALTRIGGER, and others
--
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/a4a10f09-9846-4c6e-b572-ed5123f0977d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Basically, many plugins contribute tokens. I think these come from the Environment inject plugin:
Build Causes
This plugin also exposes the cause of the current build as an environment variable. A build can be triggered by multiple causes at the same time e.g. an SCM Change could have occurred at the same time as a user triggers the build manually.
The build cause is exposed as a coma separated list:
BUILD_CAUSE=USERIDCAUSE, SCMTRIGGER, UPSTREAMTRIGGER
In addition, each cause is exposed as a single envvariable too:
BUILD_CAUSE_USERIDCAUSE=true
BUILD_CAUSE_SCMTRIGGER=true
BUILD_CAUSE_UPSTREAMTRIGGER=true
It looks like you can get the user id
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/ef08a7f4-380f-40da-bcc3-649188688ee1%40googlegroups.com.
Basically groovy script are just like java code with syntactical sugar. I mean if you find the Jenkins api you want to use, doing it in groovy is generally very very easy.
In your case the "hardest" part is getting hold onto the current build reference in a system groovy script in a build step. Then the rest is east as you already found where to begin (if not have a look at the build trigger badge plugin code [shameless plug]).
And if this if something you want to offer as a simple build feature, then writing a plugin might even be a good and quite simple way too.
Cheers
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f08241c9-98cd-46e9-9c4d-47e80ee84a30%40googlegroups.com.
manager.build.getCauses().each { cause ->
cause.toString() == "job/projectA/148[job/projectA/14[hudson.model.Cause$UserIdCause@caebc9aa]]"
cause.getClass() == "class hudson.model.Cause$UpstreamCause"
}manager.build.getCauses().each { cause ->
cause.toString() == "job/projectB/14[hudson.model.Cause$UserIdCause@caebc9aa]"
cause.getClass() == "class hudson.model.Cause$UpstreamCause"
}if (cause.getShortDescription().contains("Started by upstream project")def userCause = manager.envVars["BUILD_CAUSE"]