5

Currently I have configured a job with Jenkinsfile to send notification in case of a failure .

catch (err) {
    currentBuild.result = "FAILED"
    mail (to: 'viveky4d4v@gmail.com',
         subject: "Job '${env.JOB_NAME}'- (${env.BUILD_NUMBER}) has FAILED",
         body: "Please go to ${env.BUILD_URL} for more details. ");

    throw err
}

Is it possible to send console logs as well in the email in case of a job failure ?

vivekyad4v
  • 13,321
  • 4
  • 55
  • 63

2 Answers2

8

If you install the email extension plugin found here https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin then you can do this with another parameter. That looks like this:

emailext attachLog: true, body: '', subject: ''

That will attach the logs as a txt file attachment to your emails, which is the method I personally use.

Or, alternatively, if you don't mind "sending the console logs" to mean "sending a URL to the console logs", you can do something similar to what jozefow recommended and change the body to...

body: "Please go to ${env.BUILD_URL}/consoleText for more details. ");
Spencer Malone
  • 1,449
  • 12
  • 12
  • That's astonishing how you can't find anywhere any mention of `attachLog`. Very useful and easy way to send an email with a build log, and yet, not documented at all (at least nowhere I could find). – Alexander Dec 19 '20 at 02:02
2

You can download console logs and attach it to email. Get logs from current build by running command: wget ${env.BUILD_URL}/consoleText -O console_text.txt

jozefow
  • 626
  • 3
  • 14
  • This is actually exactly what I was looking for when looking for this, is a way to down load the console_text and send it on slack, since the jenkins instance we use is not public facing, but the console text isn't black listed. – Caperneoignis May 17 '19 at 17:02