Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-72068

In a HTML email body, `${SOME:TEXT}` is not interpreted correctly and ends up in an Error processing tokens

XMLWordPrintable

      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:

            slide_o_mix Alex Earl
            aneveux Antoine Neveux
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: