Originally published on 2015-10-03; fully revised and updated.
If your team depends on Jenkins email alerts, putting the right build-log content in the email body can speed up incident triage. This guide explains how to use Email Extension (email-ext) content tokens for full logs and regex-filtered snippets, plus practical examples you can copy into job configuration or Pipeline.

Choose the right log-in-email strategy
There are two common approaches: include the whole log, or include only matched lines (with context). The second option keeps emails concise when builds produce large output.
| Token or link | What it adds to the email | Best for | Trade-off |
|---|---|---|---|
${BUILD_LOG, maxLines=9999, escapeHtml=false} | Full (or near-full) build console output | Small/medium logs, immediate context | Can create very long and noisy emails |
${BUILD_LOG_REGEX, ...} | Only lines matching a regex, optionally with lines before/after | Failure summaries, error-first notifications | Needs careful regex tuning |
${BUILD_URL}/artifact/ | Link to build artifacts | Reports, logs, packaged outputs | Requires Jenkins access and artifact retention |
${PROJECT_URL}/ws/ | Link to workspace | Quick inspection in trusted/internal environments | May be inaccessible or restricted by security settings |
How email-ext token rendering works in notifications
When a job trigger fires an email-ext notification, Jenkins resolves tokens in the subject/body and injects log content based on token parameters.
flowchart TD
A[Build runs in Jenkins] --> B[Email trigger condition met]
B --> C[email-ext composes message]
C --> D{Token used in body}
D --> E[BUILD_LOG inserts full log]
D --> F[BUILD_LOG_REGEX filters by pattern]
E --> G[Email sent to recipients]
F --> G
G --> H[Team triages result]
Way 1: Include the full build log in the email body
For freestyle-style configuration, place a BUILD_LOG token in the email-ext content field (for example, in Default Content or job-level editable email content).
- Open the job configuration and locate Email Extension settings.
- Add the build-log token to the email body template.
- Save and run a build to verify output length and readability.
${BUILD_LOG, maxLines=9999, escapeHtml=false}Code language: JavaScript (javascript)
If your logs are large, reduce maxLines and consider escapeHtml=true to avoid accidental HTML rendering in messages.
Way 2: Include only specific lines with regex
Use BUILD_LOG_REGEX to send only important lines (for example failures, specific error codes, or a small context window around matched patterns).
${BUILD_LOG_REGEX, regex="\\b(Buildfile|BUILD)\\b", linesAfter=1}
${BUILD_LOG_REGEX, regex="^.*?BUILD FAILED.*?$", linesBefore=0, linesAfter=10, maxMatches=5, showTruncatedLines=false, escapeHtml=true}
${BUILD_LOG_REGEX, regex="\\b(FC0)\\b", linesAfter=1}
${BUILD_LOG_REGEX, regex="^.*?FC0.*?$", maxMatches=95, showTruncatedLines=false, escapeHtml=false, matchedLineHtmlStyle=true}Code language: JavaScript (javascript)
Regex parameter quick reference
| Parameter | Purpose | Typical usage |
|---|---|---|
regex | Pattern to match in console output | Find failure lines, warnings, IDs |
linesBefore / linesAfter | Add context around each match | Show stack trace or command around error |
maxMatches | Limit number of matched sections | Avoid oversized messages |
showTruncatedLines | Control truncation markers | Keep output clean for readers |
escapeHtml | Escape HTML-sensitive text | Safer rendering for email clients |
Useful tokens and formatting tips for email body templates
${PROJECT_URL}/ws/
${BUILD_URL}/artifact/
${BUILD_LOG, maxLines=1000}
String-argument escaping in token parameters follows the original guidance: escape quotes and backslashes inside arguments. For HTML emails, line breaks are typically added with <br>.
arg1="\"quoted\""; arg2="c:\\path"; arg3="one\\ntwo"Code language: JavaScript (javascript)
Pipeline example using emailext
If you send notifications from Jenkins Pipeline, you can keep tokenized content in the emailext body.
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'make test'
}
}
}
post {
failure {
emailext(
subject: "Build failed: ${env.JOB_NAME} #${env.BUILD_NUMBER}",
to: 'team@example.com',
body: '''Build URL: ${BUILD_URL}<br/>
Artifacts: ${BUILD_URL}/artifact/<br/><br/>
${BUILD_LOG_REGEX, regex="^.*?BUILD FAILED.*?$", linesBefore=0, linesAfter=15, maxMatches=5, escapeHtml=true}'''
)
}
}
}Code language: PHP (php)
Original references
- http://wiki.hudson-ci.org/display/HUDSON/Email-ext+plugin
- http://stackoverflow.com/questions/9439450/how-will-i-filter-out-only-errors-in-jenkins-email-ext-build-log-regex
- http://champasoft.blogspot.nl/2012/11/jenkins-pattern-for-e-mailing-log.html
- https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin
- Original embed context mentioned this troubleshooting video link: https://www.youtube.com/watch?v=ZCfrNvu6nMc
Common pitfalls
- Sending too many log lines can cause unreadable or clipped emails.
- Using
escapeHtml=falsemay render raw HTML from logs in email clients. - Regex patterns often fail due to missing escaping; validate on a sample failed build.
- Workspace and artifact links depend on Jenkins URL configuration, permissions, and retention.
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals