Marmstrong
Marmstrong

Reputation: 1786

Include Build request user in jenkins groovy email

After a build is finished I use the mail-ext-plugin (Jenkins Email Extension Plugin) to send an email to certain users. I would like to include the user who started (requested) the build in that email. I have tried the suggestion here however, that didn't seem to work I just got this error.

Error in script or template: groovy.lang.MissingPropertyException: No such property: CAUSE for class: SimpleTemplateScript4

Upvotes: 0

Views: 931

Answers (2)

Noam Manos
Noam Manos

Reputation: 16971

To avoid groovy.lang.MissingPropertyException: No such property: Cause for class, you can try to import hudson.model.Cause, or even better - directly call the currentBuild.getBuildCauses(), instead of importing 'Cause' class.

For example:

String buildUserName = currentBuild.getBuildCauses()[0].userName
String buildDescription = currentBuild.getBuildCauses()[0].shortDescription

If the above didn't work, try also:

def userCause = currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause')
String buildUserName = userCause.userName[0] ?: "Unknown"
String buildDescription = userCause.shortDescription[0] ?: "Unknown"

Upvotes: 0

Marmstrong
Marmstrong

Reputation: 1786

After much searching I found a page on jelly usage on the Jenkins wiki (here). There is a link on this page which contains all the useable classes. I was able to find the cause class and used this great example to help me implement it in my code. I added

<%
    for (hudson.model.Cause cause : build.causes) {
%>
        ${cause.shortDescription}
<%
    }
%>

which produced -

Started by user Matthew Armstrong

Upvotes: 1

Related Questions