6

I am trying to use "${BUILD_LOG, maxLines, escapeHtml}" like discribed in: How can I take last 20 lines from the $BUILD_LOG variable?

Unfortunately it doesn't work for me.

I get this error:

Script1.groovy: 114: expecting anything but ''\n''; got it anyway @ line 114, column 301. arted by user MYUSERNAME

My code in this line is:

          msg.setText("This build (" + build.getFullDisplayName() 
          + " ) contains the following tasks:\n\nTASK\t\t\t  IMPLEMENTER:\n" 
          + taskList + "\n\n\nLink to this 
          build: ${BUILD_URL} \n ${BUILD_LOG, maxLines=9999, escapeHtml=false}" );

If I take this out the following, it works. Thats why my guess is, that "BUILD_LOG" is not working anymore?

${BUILD_LOG, maxLines=9999, escapeHtml=false}


EDIT: Maybe as addition: I am trying to do this withing the PreSend groovy script. Since I am building the Email text dynamically. ${BUILD_URL} works fine, ${BUILD_LOG, maxLines=9999, escapeHtml=false} doesn't (for me) i am looking for a solution for this... the msg object is a java MimeMessage.

Thanks, Daniel

Community
  • 1
  • 1
Beasly
  • 1,517
  • 4
  • 20
  • 30

4 Answers4

1

That error message is usually related to not closed quotes, comments started with / instead of //, etc. In your code the only thing I can see is that your third line is not finished properly, i.e., after "\n\n\nLink to this you are not closing double quotes and instead you are starting a new line (thereby the expecting anything but ''\n''.

Try to write the whole line:

msg.setText("This build (" + build.getFullDisplayName() 
          + " ) contains the following tasks:\n\nTASK\t\t\t  IMPLEMENTER:\n" 
          + taskList + "\n\n\nLink to this build: ${BUILD_URL} \n ${BUILD_LOG, maxLines=9999, escapeHtml=false}" );

or close the quotes instead:

msg.setText("This build (" + build.getFullDisplayName() 
          + " ) contains the following tasks:\n\nTASK\t\t\t  IMPLEMENTER:\n" 
          + taskList + "\n\n\nLink to this "
          + "build: ${BUILD_URL} \n ${BUILD_LOG, maxLines=9999, escapeHtml=false}" );
jalopaba
  • 8,039
  • 2
  • 44
  • 57
  • thanks for your input. Actually I did this, to have it readable here. Right now it is all in one line. So the quote "+ taskList + "\n\n\nLink" goes until the end. Because I had the same thought (more or less), just tried to solve it differently... – Beasly Sep 29 '15 at 11:51
  • Yes :( even with: ${BUILD_LOG} alone in the string. – Beasly Sep 29 '15 at 12:14
  • Watch that the error says "column 301"... search for a quite long line in your script. I'm quite sure it has to do with not closed quotes... Putting the hole line together (even with white spaces) I only get 265 chars. – jalopaba Sep 29 '15 at 15:25
  • You are right, I never reach this length. But it doesn't eplain why without this it just works. No additional brackts or quotes. Have u tried this on your side? I mean, I spent quite some time trying and searching the nets, before looking for my SO pw and ask here... :S – Beasly Sep 30 '15 at 12:33
0

I used the below and it's working fine for me.

${BUILD_LOG, maxLines=10, escapeHtml=false}

I tried with Jenkins version 1.617

Triangle
  • 1,477
  • 3
  • 22
  • 36
  • This exactly what I wrote... ?! and It's not working for me with: Jenkins ver. 1.609.2 (LTS) see the example above... I tried also with less and without maxLines... no change – Beasly Sep 29 '15 at 07:14
0

Have you tried to set escapeHtml=true? It may happen that this token expanded as is and then string in " " becomes not valid.

  • Will give it a try :) – Beasly Oct 01 '15 at 05:33
  • Unfortunately i doesn't work either. I always points to a colum which doesn't exist. and the "^" pointing to the error point to my username. I really had high hopes here. Also tried mail content as HTML and plain text... no change, as soon as "${BUILD_LOG, maxLines=9999, escapeHtml=true}" is within the string... thanks though for giving it a thought... – Beasly Oct 01 '15 at 09:48
  • Maybe try get build_log content into variable and escape new lines with .replace("\", "\\")? Then it shouldn't break string in `setText()`. – Kanstantsin Shautsou Oct 01 '15 at 16:54
  • Sorry for the late response, I was busy with other stuff. This doesn't allow me to "embed" the log file as attachment just like this. If I use BUILD_LOG_REGEX, I don't get an error, but neither an attached log :( – Beasly Oct 16 '15 at 08:46
0

In latest version variable ${BUILD_LOG} wasn't available for me - only solution to get log in email content was for me setting:

msg.setText(build.getLog())

as Default Pre-send Script in Jenkins global configuration...

Strinder
  • 2,111
  • 2
  • 21
  • 34