Include Build request user in jenkins mail

In your example, {$BUILD_USER} should be ${BUILD_USER},
but even this way it will not work unless you install this Plugin:

Build User Vars Plugin

It gives you the following variables:

  • BUILD_USER – full name of user started build,
  • BUILD_USER_FIRST_NAME – first name of user started build,
  • BUILD_USER_LAST_NAME – last name of user started build,
  • BUILD_USER_ID – id of user started build.

(see the plugin page for more details)


SIMPLE SOLUTIONS (WITHOUT ANY PLUGINS / NO PLUGINS) !!

METHOD 1: Via Shell

BUILD_TRIGGER_BY=$(curl --silent ${BUILD_URL}/api/xml | tr '<' '\n' | egrep '^userId>|^userName>' | sed 's/.*>//g' | sed -e '1s/$/ \//g' | tr '\n' ' ')
echo "BUILD_TRIGGER_BY: ${BUILD_TRIGGER_BY}"

METHOD 2: Via Groovy

node('master') {
BUILD_TRIGGER_BY = sh ( script: "curl --silent ${BUILD_URL}/api/xml | tr '<' '\n' | egrep '^userId>|^userName>' | sed 's/.*>//g' | sed -e '1s/\$/ \\/ /g'", returnStdout: true ).trim()
echo "BUILD_TRIGGER_BY: ${BUILD_TRIGGER_BY}"
}

METHOD 3: Via Groovy

BUILD_TRIGGER_BY = "${currentBuild.getBuildCauses()[0].shortDescription} / ${currentBuild.getBuildCauses()[0].userId}"
echo "BUILD_TRIGGER_BY: ${BUILD_TRIGGER_BY}"

OUTPUT:

Started by user Admin / [email protected]

Note: Output will be both User ID and User Name


I realise I'm replying to a 4-year-old question here, but Google brought me here so others may find this information useful...

There have been many changes to the Email-ext Jenkins plugin over the last few years, which affect this question - for example, in v2.38 (May 24, 2014):

Implemented new extension point for recipient providers (RecipientProvider) this changes the way that recipient types are added

There are no longer checkboxes for "Requestor" "Recipients" etc, each is provided by an implementation of a RecipientProvider

Using the latest version of the plugin, if you wish to send an email to the user who triggered a build, you can simply select "Requestor" from the "Send To" trigger options:

jenkins screenshot

The "Recipient List" is a hard-coded list which you can also define for the job.


I have finally found what I wanted, adding:

$CAUSE

or

${CAUSE}

gives

Started by user Jan Jansen