How do I attach a build log to an e-mail notification with the Jenkins plugin Email-ext?
You may just use ${BUILD_LOG, maxLines, escapeHtml} token in the body of the e-mail to include the build log.
Quoting the email-ext plugin doc (available here):
"To see a list of all available email tokens and what they display, you can click the "?" (question mark) associated with the Content Token Reference at the top bottom of the email-ext section on the project configuration screen"
The plugin DOES support attaching the build log, you just need to check the box in the project configuration.
After sleeping on the problem and doing more research, I came to the conclusion that Email-ext does not support the attachment of a build log to a build notification e-mail.
However, I did come up with a sneaky work-around to use until such a feature is available: I use the Jenkins build tokens to generate the appropriate command to copy the log file from the master server to the slave's build workspace (see note below).
In the project, after the main compilation step, I added a new Execute shell step to generate the appropriate scp
(secure copy) command. This is the command (replace USER and HOSTNAME with your own values, and you'll probably need to tailor the path to suit your individual server):
scp USER@HOSTNAME:/var/lib/jenkins/jobs/$JOB_NAME/builds/$BUILD_ID/log build.log
Then, in the Email-ext Attachments field of the Email-ext plugin, I entered:
build.log
Now the build log is copied from the master to the slave's workspace and attached to build notification e-mail messages. I have removed the $BUILD_LOG
token from the message body template.
Note: to use this particular technique, you'll need to have passwordless ssh configured between the slave and the master, perhaps using an OpenSSH key passphrase. If you need help with that, search around the web for information on the ssh-keygen
command, and perhaps check tutorials like this one. A similar approach should work on platforms that do not have built-in support for SSH. RoboCopy or similar should work on Windows systems.
EDIT: The Email-ext plug-in now has the ability to attach a build log to a notification message with a check-box on the job's configuration screen. See slide's answer for an example.