forked from jenkinsci/pipeline-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use whitelisted APIs from workflow-support 2.22
- Loading branch information
Showing
1 changed file
with
19 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
// There is no direct access to the build Causes from the Pipeline, but you can | ||
// get this by using the `currentBuild.rawBuild` variable, as shown below. | ||
// As of Pipeline Supporting APIs v2.22, there is a whitelisted API to access | ||
// build causes as JSON that is available inside of the Pipeline Sandbox. | ||
|
||
// Get all Causes for the current build | ||
def causes = currentBuild.rawBuild.getCauses() | ||
def causes = currentBuild.getBuildCauses() | ||
|
||
// Get a specific Cause type (in this case the user who kicked off the build), | ||
// if present. | ||
def specificCause = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause) | ||
def specificCause = currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause') | ||
|
||
// If you see errors regarding 'Scripts not permitted to use method...' approve | ||
// these scripts at JENKINS_URL/scriptApproval/ - the UI shows the blocked methods | ||
|
||
// See the Javadoc for Cause for more information on what's in Causes, etc at: | ||
// http://javadoc.jenkins-ci.org/hudson/model/class-use/Cause.html | ||
// The JSON data is created by calling methods annotated with `@Exported` for | ||
// each Cause type. See the Javadoc for specific Cause types to check exactly | ||
// what data will be available. | ||
// For example, for a build triggered manually by a specific user, the resulting | ||
// JSON would be something like the following: | ||
// | ||
// [ | ||
// { | ||
// "_class\": "hudson.model.Cause$UserIdCause", | ||
// "shortDescription": "Started by user anonymous", | ||
// "userId": "tester", | ||
// "userName": "anonymous" | ||
// } | ||
// ] | ||
// cf. https://javadoc.jenkins-ci.org/hudson/model/Cause.UserIdCause.html |