MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Jenkins Email-ext: Include Build Logs in Email Body (Full Log or Regex-Filtered)

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.

Jenkins build log in email body example

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

OptionBest forMain controlsTrade-off
BUILD_LOGComplete log contextmaxLines, escapeHtmlCan create very large emails
BUILD_LOG_REGEXFocused alerts (errors, markers)regex, linesBefore/After, maxMatches, escapeHtmlNeeds 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

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
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.

Related Posts

Jenkins Email-ext: Add Full or Regex-Filtered Build Logs to Email Body

Learn how to include Jenkins build logs directly in notification emails using email-ext tokens. This revised guide covers full-log and regex-filtered approaches for freestyle jobs and Pipeline templates.

Read More

Jenkins at Scale: Practical References and Admin Cheatsheet

This revised guide upgrades a short 2015 Jenkins link post into an operations-ready reference for teams running Jenkins at scale. It preserves the original links and adds a workflow diagram, comparison table, and practical API/CLI examples.

Read More

Foodcritic for Chef Cookbooks: Practical Linting and Jenkins CI for Legacy Pipelines

Foodcritic helps you statically lint Chef cookbooks for style, correctness, and common anti-patterns before convergence fails in production. This guide shows how to run it locally, wire it into Jenkins, and enforce fail policies that teams will actually use.

Read More

Jenkins Backup and Restore Runbook: ThinBackup, Filesystem Archives, and Recovery Steps

A practical Jenkins backup and restore guide for DevOps teams, covering what to back up, strategy trade-offs, and step-by-step command examples. Includes a workflow diagram and a recovery checklist you can operationalize.

Read More

Jenkins Troubleshooting Guide: Fast Triage, Log Analysis, and Common Failure Fixes

A practical Jenkins troubleshooting guide for DevOps teams: find the right logs first, separate controller vs. agent vs. job failures, and resolve common outage patterns quickly.

Read More

Jenkins Interview Questions, Answered: CI, APIs, Installation, Backups, and Essential Plugins

This revised guide turns common Jenkins interview prompts into practical answers you can explain with confidence. It covers CI fundamentals, API usage, setup on Ubuntu and RHEL-like systems, backup strategy, and key plugins.

Read More
Subscribe
Notify of
guest
3 Comments
Newest
Oldest Most Voted
Puja kushwaha
Puja kushwaha
1 month ago

Adding Jenkins build logs to email alerts can help developers find the cause of a failure much faster. It is best to include the key error lines rather than sending a huge log in every message. A link to the full console output gives the team more detail when needed. Email templates should also make the job name, build number, and result easy to spot. Always check logs for secrets before sharing them through email.

Rajesh
Rajesh
1 month ago

A useful improvement to Jenkins email alerts is to make the log content actionable rather than simply forwarding raw output. For example, a notification could identify the failed stage, include the last relevant error lines, and show the build number and commit that introduced the change. Teams should also consider email delivery failures and avoid sending notifications for every minor event, as excessive alerts quickly lose their value. A well-designed notification system helps developers identify the cause of a failure faster without having to search through lengthy console logs every time.

Art Vandeley
Art Vandeley
4 years ago

This does not work

3
0
Would love your thoughts, please comment.x
()
x