Skip to content

Commit 3fcac4a

Browse files
committed
Use whitelisted APIs from workflow-support 2.22
1 parent 0b834c0 commit 3fcac4a

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
// There is no direct access to the build Causes from the Pipeline, but you can
2-
// get this by using the `currentBuild.rawBuild` variable, as shown below.
1+
// As of Pipeline Supporting APIs v2.22, there is a whitelisted API to access
2+
// build causes as JSON that is available inside of the Pipeline Sandbox.
33

44
// Get all Causes for the current build
5-
def causes = currentBuild.rawBuild.getCauses()
5+
def causes = currentBuild.getBuildCauses()
66

77
// Get a specific Cause type (in this case the user who kicked off the build),
88
// if present.
9-
def specificCause = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause)
9+
def specificCause = currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause')
1010

11-
// If you see errors regarding 'Scripts not permitted to use method...' approve
12-
// these scripts at JENKINS_URL/scriptApproval/ - the UI shows the blocked methods
13-
14-
// See the Javadoc for Cause for more information on what's in Causes, etc at:
15-
// http://javadoc.jenkins-ci.org/hudson/model/class-use/Cause.html
11+
// The JSON data is created by calling methods annotated with `@Exported` for
12+
// each Cause type. See the Javadoc for specific Cause types to check exactly
13+
// what data will be available.
14+
// For example, for a build triggered manually by a specific user, the resulting
15+
// JSON would be something like the following:
16+
//
17+
// [
18+
// {
19+
// "_class\": "hudson.model.Cause$UserIdCause",
20+
// "shortDescription": "Started by user anonymous",
21+
// "userId": "tester",
22+
// "userName": "anonymous"
23+
// }
24+
// ]
25+
// cf. https://javadoc.jenkins-ci.org/hudson/model/Cause.UserIdCause.html

0 commit comments

Comments
 (0)