Jenkins Email-ext help - accessing build log in email

1,288 views
Skip to first unread message

Ghazi TRIKI

unread,
Feb 1, 2017, 11:20:21 AM2/1/17
to Jenkins Users

Hello,

I am helping Siva on a Jenkins build task. We wrote a pipeline email function that get log and puts it to email. The issue we have is that we tried using BUILD_LOG_EXCERPT and BUILD_LOG variables but get the following exception. Can you help us please?

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 17: unexpected token: BUILD_LOG_EXCERPT @ line 17, column 11.
         <pre>${BUILD_LOG_EXCERPT, start="^Hello World", end="^Finished: SUCCESS"}</pre>""",

Slide

unread,
Feb 1, 2017, 11:40:04 AM2/1/17
to Jenkins Users
If you are including this in a pipeline script, you need to make sure and use single quotes or escape the $. Groovy will try and evaluate that if you use double quotes.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/aa987e90-2a58-4909-88fc-2773f666d0a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ghazi TRIKI

unread,
Feb 1, 2017, 12:30:40 PM2/1/17
to Jenkins Users
Can you please give an example of what we need to use?

siva varma Datla

unread,
Feb 1, 2017, 12:32:06 PM2/1/17
to Jenkins Users
Can you provide me with an example please!!
I would appreciate it if you do so

Slide

unread,
Feb 1, 2017, 12:48:47 PM2/1/17
to Jenkins Users
Use single quotes instead of double quotes, I don't know how else to say it.

siva varma Datla

unread,
Feb 1, 2017, 1:03:01 PM2/1/17
to Jenkins Users
I am attaching the whole groovy Syntax I am using to get an email notification when build is started I also want to include some part of console log starting from Hello World to Finished Success.

When I try with single quotes I end up this 
ERROR:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 17: unexpected token: BUILD_LOG_EXCERPT @ line 17, column 12.
   	  '<pre>${BUILD_LOG_EXCERPT, start="^Hello World", end="^Finished: SUCCESS"}</pre>'""",



GROOVY SYNTAX

node {
   echo 'Hello World'
}
node {

  notifyStarted()

  /* ... existing build steps ... */
}

properties = ([data])
def notifyStarted() {
   emailext (
      subject: "STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
      body: """<p>STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
 <p>Check console output at &QUOT;<a href='${env.BUILD_URL}consoleText'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>&QUOT;</p>""",
 '<pre>${BUILD_LOG_EXCERPT, start="^Hello World", end="^Finished: SUCCESS"}</pre>'
     to: 'sivaver...@ncr.com'
    )
}

Slide

unread,
Feb 1, 2017, 1:06:56 PM2/1/17
to Jenkins Users
body : """..."""

You are using double quotes...use single quotes

body : '''...'''

Arnab Banerjee

unread,
Sep 27, 2017, 2:09:07 AM9/27/17
to Jenkins Users
Hi Siva,

Did you find a solution for this? I also in need of similar use case and need to send part of console output as part of email body using a pipeline script and evaluating options of emailext plugin.
Reply all
Reply to author
Forward
0 new messages