1

I am trying to email the console o/p in HTML format using pipeline script. However, it doesn't seem to be working. Any suggestions.

    def notifySuccessful() {
emailext (
      subject: "STARTED: Job ${env.JOB_NAME} [${env.BUILD_NUMBER}]",
      body: '<pre>${BUILD_LOG_EXCERPT, start="^Hello World", end="^Finished: SUCCESS"} </pre>',
    to: 'myemail.com'
    )
    }

When I run this, I get the email with the below text in the body

${BUILD_LOG_EXCERPT, start="^Hello World", end="^Finished: SUCCESS"} 
.

I tried with putting ''' or """" or ' to the line

${BUILD_LOG_EXCERPT, start="^Hello World", end="^Finished: SUCCESS"} 

but that doesn't work either. If I enclosed with a single ", I get an error that says

unexpected token BUILD_LOG_EXCERPT

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Bond
  • 855
  • 3
  • 13
  • 24

1 Answers1

2

Here you are prudviraj's answer, which explains clearly how BUILD_LOG_EXCERPT regex works.

Here you are my email-ext code

emailext (
            mimeType: "text/html",
            to: "your_email",
            subject: "Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
            body:'''<html>Build ! 
                    <br />
                    Check console output at <a href="$BUILD_URL">${JOB_NAME} [${BUILD_NUMBER}]</a> 
                    <br /> 
                    <br />
                    <pre>${BUILD_LOG_EXCERPT, start="Started by user Admin user", end="test"}</pre></html>'''
        )

The console output

enter image description here

And the email received

enter image description here

Lesly Bernaola
  • 393
  • 1
  • 12
  • I think I am using the same as code but it doesn't seem to work. Please see the code snippet above. – Bond Dec 01 '17 at 22:57
  • I am using the same code with ''', the only difference with your code is I defined the body in another variable before using it in the emailext. – Lesly Bernaola Dec 01 '17 at 23:25
  • Would you mind sharing your code snippet? I tried it in several ways and all I get is the text
    ${BUILD_LOG_EXCERPT, start="^Hello World", end="^Finished: SUCCESS"} 
    in the o/p but not in html converted format
    – Bond Dec 02 '17 at 00:00
  • This is what I get in the console o/p. So it looks like it is not expanding the token Proceeding [Pipeline] emailext Job type does not allow token replacement. Job type does not allow token replacement. Job type does not allow token replacement. Job type does not allow token replacement. Sending email to: – Bond Dec 02 '17 at 00:24
  • I added a code example to my answer. I really don't know why your are not able to replace the token, pay attention to the regex for start and end ([java.util.regex.Pattern](https://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)). – Lesly Bernaola Dec 03 '17 at 17:05
  • Thanks much @Lesly. Much appreciated. For some reason, my code still doesn't work and I am beginning to wonder if the version of the plugin is playing any tricks.. I will keep posted. – Bond Dec 03 '17 at 22:33
  • I can't get this working no matter how/what I tried. It doesn't interpret the REGEX and prints the command text only. I am using 2.47 version if that has any bugs. – Bond Dec 04 '17 at 05:23