Daniel SMith
Daniel SMith

Reputation: 53

Read Jenkins build console output and set email content

I have certain errors which I set in my code, which should add corresponding error messages to the email content of the final build email.

I was thinking of printing something such as ("EMAIL CONTENT ERROR: _______") to the console, reading through it (in a pre-send groovy script?), and adding corresponding error messages for each error found.

I was thinking of using a pre-send groovy script, setting the mimeMessage object(was reading jenkins email-ext documentation). Would this be viable?

Also, I have never used groovy before, so pointers to how to approach this would be extremely helpful(or a link to where i can find an implementation of something with a similar idea of reading console). Any advice would be greatly appreciated. Thanks in advance!

Upvotes: 1

Views: 3803

Answers (2)

writerrajiv
writerrajiv

Reputation: 114

Can you check attaching "Build Log" This would highlight all the process of build process.

Upvotes: 1

IanAWP
IanAWP

Reputation: 509

This is a very similar concept to the question here. The technique there was to use the log parser plugin to scan the console output for you, and then use groovy to add all the errors into an email.

This is generally a pretty good idea because it also means that you can view the same set of highlighted errors from jenkins itself, rather than just the email.

There are a couple of ways this is different from your setup, the main points are:

  1. Yes, write errors directly to the console in a known format
  2. Set the log parser up with regular expressions that find your error format
  3. Instead of a pre-send script, in this case you would use a groovy template for your email generation
  4. The template reads the error list from the console parser and adds them to your email. Each one is a link that links back to the jenkins console output.

Upvotes: 0

Related Questions