Created
April 18, 2016 09:25
-
-
Save jaysoncena/4b18951c3c5e68a9049ad340878761e9 to your computer and use it in GitHub Desktop.
Jenkins - Get the user who triggered the current or the parent job
This file contains hidden or 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
def triggeredBy = "---" | |
def iterateCause(b) { | |
upstreamcause = b.getCause(hudson.model.Cause.UpstreamCause.class) | |
if (upstreamcause != null) { | |
job = Jenkins.getInstance().getItemByFullName(upstreamcause.getUpstreamProject(), hudson.model.Job.class) | |
if (job != null) { | |
upstream = job.getBuildByNumber(upstreamcause.getUpstreamBuild()) | |
if (upstream != null) { | |
iterateBuild(upstream) | |
} | |
} | |
} | |
usercause = b.getCause(hudson.model.Cause.UserIdCause.class) | |
if (usercause != null) { | |
triggeredBy = usercause.getUserName() | |
} | |
return; | |
} | |
iterateCause(build) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wasn't authorized to use the
rawBuild
method, so I did it like this: