Currently I have configured a job with Jenkinsfile to send notification in case of a failure .
catch (err) {
currentBuild.result = "FAILED"
mail (to: '[email protected]',
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 ?
Go to the Jenkins home page and click the 'Manage Jenkins' menu option. Then, select the 'Configure System' option. Enter the SMTP server name under 'Email Notification'. Click the 'Advanced' button and then click the checkbox next to the 'Use SMTP Authentication' option.
In order to read the console output in Jenkins, All you need to do is copy and paste the code as a stage in your pipeline script. After the build is run, a file named buildConsolelog. txt will be stored in the home directory of your project.
Select “Configure”. Select “Add post-build action” and Click “E-Mail Notification”. Enter your recipients mail address and select first option “Send e-mail for every unstable build”. Click “Save” button.
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. ");
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With