Username of active directory user who started the build using API token

81 views
Skip to first unread message

Mandy

unread,
Jul 24, 2015, 4:23:21 PM7/24/15
to Jenkins Users
I have active directory authentication on Jenkins and I am launching job remotely using the following command line

curl -u  testuser:7658756hfjsdngsd8908593486 http://jenkinsserver:8080/job/testjob/build?token=onlytest

How can I using groovy get access to this username in the job?

Thanks,
Mandy


Christopher Orr

unread,
Jul 24, 2015, 4:36:28 PM7/24/15
to jenkins...@googlegroups.com
The solution is essentially the same as your last question about getting
the IP address of a user starting a job.

If the user was started by a logged-in user, the "cause" of the build
will be UserCause, rather than RemoteCause:

https://github.com/jenkinsci/jenkins/blob/ed2988f/core/src/main/java/hudson/model/Cause.java#L374-L376

Mandy

unread,
Jul 24, 2015, 5:00:52 PM7/24/15
to Jenkins Users, ch...@orr.me.uk
The build is not being started by the logged in user. It is started by another user on a remote machine using some other account credentials on command line. It looks like following

User test1 is looged into Jenkins
User test2 is logged into some remote machine and specifies "testuser" credentials in command line.

Mandy

unread,
Jul 28, 2015, 7:18:56 PM7/28/15
to Jenkins Users, ch...@orr.me.uk, mand...@gmail.com
Anyone?

Christopher Orr

unread,
Jul 28, 2015, 8:51:07 PM7/28/15
to jenkins...@googlegroups.com
Are you not seeing the information you need in the causes? What are you
seeing instead?
> --
> 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
> <mailto:jenkinsci-use...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/fb0514f8-14cb-4781-a134-2d121e7fc43b%40googlegroups.com
> <https://groups.google.com/d/msgid/jenkinsci-users/fb0514f8-14cb-4781-a134-2d121e7fc43b%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Mandy

unread,
Jul 30, 2015, 6:16:41 PM7/30/15
to Jenkins Users, ch...@orr.me.uk
I specified UserCause instead of RemoteCause and it still says:

Started by remote host xx.xx.xx.xx
Script returned: []

=================================================
import hudson.model.*
build.getCauses().grep(hudson.model.Cause.UserCause).each { 
  def findcause = it.getUserName()
  println findcause
}
=================================================
Thanks,
Mandy
Reply all
Reply to author
Forward
0 new messages