-
Bug
-
Resolution: Won't Do
-
Minor
-
None
Using email-ext-plugin, when writing a String like <pre>${SOME:TEXT}</pre> in the email body, the String is not processed properly and results in Error processing tokens. Note that using the String <pre>${SOME_TEXT}</pre> does not lead in an error and works properly.
This happens even in the latest version of the plugin.
How to reproduce?
- Start a Jenkins instance with email-ext-plugin installed,
- Configure SMTP
- Use the following pipeline:
#!/usr/bin/env groovy // NOTE: The only difference between these two reports is the content in the <pre> block. _ vs : def GOOD_HTML_REPORT = '''\ <html> <body> <table> <tr> <td><pre>${SOME_TEXT}</pre></td> </tr> </table> </body> </html> '''.stripIndent() def BAD_HTML_REPORT = '''\ <html> <body> <table> <tr> <td><pre>${SOME:TEXT}</pre></td> </tr> </table> </body> </html> '''.stripIndent() pipeline { agent any stages { stage('Test') { steps{ writeFile file: "GoodHTMLReport.html", text: GOOD_HTML_REPORT writeFile file: "BadHTMLReport.html", text: BAD_HTML_REPORT } post { success { // THIS WORKS - Results in email with "${SOME_TEXT}" emailext( from: "someemail@company.com", to: "youremail@company.com", // MODIFY THIS TO YOUR EMAIL ADDRESS subject: "email-ext-plugin issue", body: '${FILE, path="GoodHTMLReport.html"}', mimeType: 'text/html' ) // THIS DOES NOT WORK - Results in email with "[Error replacing 'FILE' - Error processing tokens]" emailext( from: "someemail@company.com", to: "youremail@company.com", // MODIFY THIS TO YOUR EMAIL ADDRESS subject: "email-ext-plugin issue", body: '${FILE, path="BadHTMLReport.html"}', mimeType: 'text/html' ) } } } } }
You will receive 2 mails: one containing ${SOME_TEXT} as expected, and the other one containing "[Error replacing 'FILE' - Error processing tokens]".
I did not get enough time to find the exact root cause, but the problem occurs from this method:
- Leading then to this line in the token macro: https://github.com/jenkinsci/token-macro-plugin/blob/5e816a80d1f6951a578901b19c2bb5a27782ea65/src/main/java/org/jenkinsci/plugins/tokenmacro/TokenMacro.java#L234