Search code examples
jenkinsbuildrequesthudson

In Jenkins, how do builds know who requested them?


I need to pass the username of the requester of a build down to the script that is actually doing the work. Looking at the console output for a particular build, the first line is always "Started by user foo," so Jenkins is clearly keeping track of who triggered the build. So it should be possible to pass that information down to the job. The question is, how?


Solution

  • The username isn't put in an easy-to-fetch environment variable, but you can get it using the xml (or json or python) api - as soon as you start a build, http://[jenkins-server]/job/[job-name]/[build-number]/api/xml is populated with details:

    <freeStyleBuild>
        <action>
            <cause>
                <shortDescription>Started by user foobar</shortDescription>
                <userName>foobar</userName>
            </cause>
        </action>
        <building>true</building>
        [...]