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

      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:

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

          Alex Earl added a comment -

          What are you trying to do with ${SOME:TEXT}? I don't understand why you have a colon in there.

          Alex Earl added a comment - What are you trying to do with ${SOME:TEXT}? I don't understand why you have a colon in there.

          This is actually a reproduction pipeline in order to see the problem.

          In the real situation, the pipeline is actually sending an HTML report containing a list of Git commit messages in the `<pre>` tag. The bug was encountered because one of the Git commits had this particular syntax in the message, and it led to the failure that can be reproduced from this simple pipeline.

          Antoine Neveux added a comment - This is actually a reproduction pipeline in order to see the problem. In the real situation, the pipeline is actually sending an HTML report containing a list of Git commit messages in the `<pre>` tag. The bug was encountered because one of the Git commits had this particular syntax in the message, and it led to the failure that can be reproduced from this simple pipeline.

          Alex Earl added a comment -

          It's an invalid token, you would need to escape it.

          Alex Earl added a comment - It's an invalid token, you would need to escape it.

          Jesse Glick added a comment -

          Please note that using token-macro on an argument passed to a Pipeline step is an antipattern. (docs) Too late to drop that compatibly but there should at least be an option to display processing on this step’s arguments and treat all arguments as literals.

          Jesse Glick added a comment - Please note that using token-macro on an argument passed to a Pipeline step is an antipattern. ( docs ) Too late to drop that compatibly but there should at least be an option to display processing on this step’s arguments and treat all arguments as literals.

          Jesse Glick added a comment -

          an option to display processing on this step’s arguments

          I suppose I meant to write suppress processing.

          Jesse Glick added a comment - an option to display processing on this step’s arguments I suppose I meant to write suppress processing.

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

              Created:
              Updated:
              Resolved: