Email-ext and Workflow/Pipeline - some tokens not being expanded?
Asked Answered
V

1

9

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.

Villalpando answered 4/3, 2016 at 10:29 Comment(2)
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-33980Monopoly
@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.Villalpando
P
4

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.

Plimsoll answered 4/3, 2016 at 15:18 Comment(2)
Can you point us to a working example? I was trying to make the email-ext plugin to work inside pipelines but it seems that that's impossible to find any usable examples. Check issues.jenkins-ci.org/browse/JENKINS-33980Monopoly
I am looking for the examples too. It seems I hit a dead endPreschool

© 2022 - 2024 — McMap. All rights reserved.