Search code examples
jenkinsjenkins-plugins

How can I get the started user inside Jenkins Job even in downstream project?


In jenkins job shell, I want to get the user who starts the build in the shell, how can I do it ?

The Build User Vars Plugin works well if this job was started by user, while it is triggered by others like upstream job, it doesn't work. The value like $BUILD_USER is empty.

see comments from author "Gavriil" in that page

This is not a bug. Build user could be identified only in case if build was started by user. If build was triggered by other cause, f.e. by timer or by end of upstream job

Though in the job console, actually I can see the user information

Started by upstream project "arctifact2slave" build number 16
originally caused by: 
Started by upstream project "create-vm" build number 5
originally caused by: 
Started by user larrycai

Any suggestions


Solution

  • I'm not really sure what you are exactly trying to achieve but the way I understand it, you could do the following.

    • Add a String parameter to your root job. Affect it the BUILD_USER variable value. ie:${BUILD_USER}

    • Then just pass the Current Build Parameters in the 'Post-build Actions -> Trigger parameterized build on other projects' section.

    The subsequent job will be able to read the variable.