Attach build logs to jenkins mail
To attach build logs to Jenkins mail notifications, you can follow these steps:
Method 1: Using the Jenkins "Attach build log" feature
- Go to your Jenkins job configuration page.
- Scroll down to the "Post-build Actions" section.
- Click on the "Add post-build action" dropdown and select "Attach build log".
- Choose the log level you want to attach (e.g., "Full log", "Error log", etc.).
- Save the changes.
From now on, whenever a build is triggered, Jenkins will attach the selected log level to the email notification.
Method 2: Using a Jenkins plugin
There are several plugins available that can help you attach build logs to Jenkins email notifications. Here are a few popular ones:
- Email-ext plugin: This plugin allows you to customize the email content and attachments. You can use the
${BUILD_LOG}
variable to include the build log in the email. - Build Log Archiver plugin: This plugin allows you to archive and attach build logs to email notifications.
- Jenkins Email Extender plugin: This plugin provides additional features for customizing email notifications, including the ability to attach build logs.
To use one of these plugins, follow these steps:
- Install the plugin from the Jenkins Plugin Manager.
- Configure the plugin according to its documentation.
- In your Jenkins job configuration page, add the plugin as a post-build action.
Method 3: Using a script
If you prefer a more manual approach, you can use a script to attach the build log to the email notification. Here's an example using Groovy:
import hudson.model.AbstractBuild
import hudson.model.BuildLog
// Get the current build
def build = Thread.currentThread().executable
// Get the build log
def log = build.getLog()
// Attach the log to the email
def email = build.getCauses().find { it instanceof hudson.model.Cause.UserCause }.getRecipient()
email.addAttachment("build-log.txt", log.getText())
Add this script as a post-build action in your Jenkins job configuration page.
Remember to adjust the script according to your Jenkins version and email notification settings.