Jenkins can insert build output directly into notification emails using the Email Extension plugin token macros. This is useful for CI/CD engineers and on-call responders who need fast failure context without opening the Jenkins console.
Originally published on 2015-09-11; fully revised and updated.

Where to configure log tokens
In classic Freestyle jobs, these tokens are typically placed in the Editable Email Notification body fields (for example, Default Content). The original post specifically notes Freestyle usage.
- Install and configure the Jenkins Email Extension plugin (email-ext).
- Enable editable email notifications in the job.
- Add token macros to the email body content.
Way 1: Send the full build log in the email body
Use this token when you want broad context and do not need filtering:
${BUILD_LOG, maxLines=9999, escapeHtml=false}Code language: JavaScript (javascript)
This was the original recommendation for Freestyle projects. Increase or reduce maxLines based on email size limits and readability.
Way 2: Send only selected lines with regex
Use BUILD_LOG_REGEX to extract only relevant log lines (for example, failures or specific markers):
${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)
These parameters control what appears around each match: linesBefore, linesAfter, maxMatches, and HTML handling flags such as escapeHtml.
BUILD_LOG vs BUILD_LOG_REGEX
| Option | Best for | Main controls | Trade-off |
|---|---|---|---|
| BUILD_LOG | Complete log context | maxLines, escapeHtml | Can create very large emails |
| BUILD_LOG_REGEX | Focused alerts (errors, markers) | regex, linesBefore/After, maxMatches, escapeHtml | Needs careful regex tuning |
How Jenkins builds the email content
flowchart TD
A[Build completes] --> B[Email-ext prepares message]
B --> C{Token macro used}
C -->|BUILD_LOG| D[Insert log up to maxLines]
C -->|BUILD_LOG_REGEX| E[Scan log using regex]
E --> F[Collect matches and context lines]
D --> G[Send email]
F --> G[Send email]
Freestyle setup example
In the email body field, many teams combine a focused excerpt and a broader fallback:
Failure summary:
${BUILD_LOG_REGEX, regex="^.*?BUILD FAILED.*?$", linesBefore=0, linesAfter=10, maxMatches=5, showTruncatedLines=false, escapeHtml=true}
Extended context:
${BUILD_LOG, maxLines=2000, escapeHtml=true}Code language: JavaScript (javascript)
Best practices
- Start with regex-based excerpts to keep alerts short and actionable.
- Prefer escapeHtml=true unless you explicitly need raw HTML rendering.
- Validate regex patterns against real failed logs before broad rollout.
- Avoid duplicate token lines in templates to reduce noisy emails.
- Confirm SMTP/email gateway size limits when using large maxLines values.
References from the original post
- 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
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
This does not work