2

Is there a way to get the hudson job initiated user name. Is it possible to get using script shell, py etc.

Lets assume I have the build # which was initiated. I know how to get the latest build info using api but would like to get a user details for a specific job.

Do you think, this will work for hudson? :) https://wiki.jenkins-ci.org/display/JENKINS/Build+User+Vars+Plugin

Thanks in advance

enthuguy
  • 405
  • 2
  • 8
  • 20

1 Answers1

1

That plugin will not work with Hudson, unless you download a very old version of the plugin. I'm not sure how many people are still using Hudson and haven't upgraded to Jenkins.


Anyway, when a user manually triggers a build, this is called a "user cause"; there are other types of cause, e.g. SCM trigger.

You can use the JSON or XML API to get the causes for a build, for example:
https://ci.jenkins-ci.org/job/remoting/lastSuccessfulBuild/api/xml?xpath=//action/cause/userId

In this case, this returns the username that caused the build to run.
Though note that there may be multiple causes for a build, and potentially other cause types that use the userId field.

This works in Jenkins, but it should also work in Hudson, but I haven't tested it.

Community
  • 1
  • 1
Christopher Orr
  • 110,418
  • 27
  • 198
  • 193
  • Thx Chris, is it possible to get the userid for a specific build #? – enthuguy Jan 24 '16 at 22:03
  • @enthuguy Yes, replace `lastSuccessfulBuild` in the URL with the build number. You can get API information for most URLs in Jenkins by adding `/api` to the end. – Christopher Orr Jan 24 '16 at 22:04