8
votes

I'm trying to use the email-ext plugin in a Jenkins pipeline job, but most of the tokens I take for granted when using email-ext in a freestyle job aren't being expanded?

e.g.

node {
    emailext body: '${DEFAULT_CONTENT}', mimeType: 'text/html', replyTo: '$DEFAULT_REPLYTO', subject: '${DEFAULT_SUBJECT}', to: '$DEFAULT_RECIPIENTS'
}

Generates the email:

Subject:

$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!

Body:

$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS: Check console output at $BUILD_URL to view the results.

Which are, in fairness, what is set in the general configuration. However, none of those tokens are expanded, and if I use them directly from workflow, they're not expanded either, e.g.

emailext body: '$PROJECT_NAME', mimeType: 'text/html', replyTo: '$DEFAULT_REPLYTO', subject: '${DEFAULT_SUBJECT}', to: '$DEFAULT_RECIPIENTS'

This would be 'okay' if I was able to reference my existing Groovy-based email templates using $SCRIPT, but those aren't expanded either.

Apologies if I'm missing something incredibly obvious - I don't have much experience with Pipeline yet - the lack of email-ext support has stopped me from moving across thus far.

I tested today by clean installing Jenkins 1.651, email-ext 2.41.3 and Pipeline 1.14.

1
Have you sorted it out? Can you please provide a response with an example? I am asking this because the plugin seems to lack documentation issues.jenkins-ci.org/browse/JENKINS-33980sorin
@sorin: I don't have any easily shareable code, but, I gave up on the templates and just implemented my own helper / email builder code in the cps-global-lib plugin, still calling into email-ext when I'm done. Duplicated effort, but I needed it.Phil McArdle

1 Answers

3
votes

The tokens are highly tied to AbstractBuild, which workflow doesn't use. So, the tokens won't be replaced correctly right now. I need to modify the token-macro plugin (which is the basis for the token expansion) so that it will work with a Run object instead of just AbstractBuild, but this is a large task that I haven't had the change to do yet. You could generate the same content using the workflow DSL.