Getting jenkins build user

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting jenkins build user

selva vignesh
Hi,
I have developed Jenkins plugin for my use. In that i am getting triggerer of build (i.e build user, who triggered a build). Now i am using Jenkins own database for user. 
If i migrate to AD, am i able to get userid from build?.
Cause.UpstreamCause upstreamCause = (Cause.UpstreamCause) run.getCause(Cause.UpstreamCause.class);
Run temp = null;
while (upstreamCause != null) {
Job job = Jenkins.getInstance().getItemByFullName(upstreamCause.getUpstreamProject(), Job.class);
if (job != null) {
temp = job.getBuildByNumber(upstreamCause.getUpstreamBuild());
if (temp != null) {
upstreamCause = (Cause.UpstreamCause) temp.getCause(Cause.UpstreamCause.class);
}
}
}
if (temp != null) {
run = temp;
}
SCMTrigger.SCMTriggerCause scmTriggerCause = (SCMTrigger.SCMTriggerCause) run.getCause(SCMTrigger.SCMTriggerCause.class);
if (scmTriggerCause != null) {
return "SCMTrigger";
}
UserIdCause cause = (UserIdCause) run.getCause(UserIdCause.class);
if (cause == null) {
return "System";
}
return cause.getUserId();

I am using above code to get build triggerer. Kindly assist.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/c6890eab-ed67-46ac-8b32-8b0cfec57b99%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Getting jenkins build user

Raihaan Shouhell
Yes the useridcause will have the information you need

On Wednesday, 22 January 2020 17:27:23 UTC+8, selva vignesh wrote:
Hi,
I have developed Jenkins plugin for my use. In that i am getting triggerer of build (i.e build user, who triggered a build). Now i am using Jenkins own database for user. 
If i migrate to AD, am i able to get userid from build?.
Cause.UpstreamCause upstreamCause = (Cause.UpstreamCause) run.getCause(Cause.UpstreamCause.class);
Run temp = null;
while (upstreamCause != null) {
Job job = Jenkins.getInstance().getItemByFullName(upstreamCause.getUpstreamProject(), Job.class);
if (job != null) {
temp = job.getBuildByNumber(upstreamCause.getUpstreamBuild());
if (temp != null) {
upstreamCause = (Cause.UpstreamCause) temp.getCause(Cause.UpstreamCause.class);
}
}
}
if (temp != null) {
run = temp;
}
SCMTrigger.SCMTriggerCause scmTriggerCause = (SCMTrigger.SCMTriggerCause) run.getCause(SCMTrigger.SCMTriggerCause.class);
if (scmTriggerCause != null) {
return "SCMTrigger";
}
UserIdCause cause = (UserIdCause) run.getCause(UserIdCause.class);
if (cause == null) {
return "System";
}
return cause.getUserId();

I am using above code to get build triggerer. Kindly assist.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/40b138dd-79de-41b0-a1c2-51617af617c1%40googlegroups.com.