Certified Jenkins Engineer
Automation and Security
Demo Built in Email Notification
Jenkins offers an integrated email notification feature that lets you alert teams on build status changes—failures, unstable builds, or when a build returns to normal. You can configure notifications at both the individual job level and in the global Jenkins settings for consistent alerting across all jobs.
Below is a quick overview of the built-in notification triggers:
Trigger | Description |
---|---|
Failure | Sends emails whenever a build fails |
Unstable | Notifies stakeholders when a build is unstable |
Back to normal | Alerts the team when a previously failing build succeeds |
Culprits | Emails users identified as responsible for build failures |
1. Enable Email Notification in a Job
- In Jenkins, open the npm-version-test job and click Configure.
- Scroll to Post-build Actions and search for Email Notification.
- Select Email Notification and enter recipient addresses (e.g., your Gmail). Optionally, enable Send separate emails to culprits for direct notifications.
- Click Apply to save.
To force a failure and test the email trigger, add the following to your build steps:
echo "Updating job config using Jenkins CLI"
npm -v
node -v
exit 1
Run the job again. You should see the build fail (e.g., Build #9):
In the console log, you’ll encounter:
ERROR: Couldn't connect to host, port: localhost, 25; timeout 60000
org.eclipse.angus.mail.util.MailConnectException: ...
Note
By default, Jenkins uses localhost:25
for SMTP. Unless you run a local mail server, this will fail. Configure a valid SMTP host and port in the global settings to resolve this.
2. Configure Global SMTP Settings
Go to Manage Jenkins → Configure System.
Scroll to Extended E-mail Notification (or Email Notification) and fill in:
Field Value SMTP server smtp.gmail.com Default user e-mail suffix (leave blank) Use SMTP Authentication ☑ Use SSL ☑ User Name [email protected] Password (Gmail app password) SMTP Port 465
- Click Test Configuration:
jakarta.mail.AuthenticationFailedException: 534-5.7.9 Application-specific password required ...
Warning
Gmail no longer accepts regular account passwords for SMTP. You must generate an app-specific password if Two-Factor Authentication (2FA) is enabled.
3. Generate a Gmail App Password
- Sign in to your Google Account and navigate to Security.
- Ensure 2-Step Verification is enabled.
- Under App passwords, click Select app → Other (Custom name), name it (e.g., "Jenkins email service"), then Generate.
- Copy the 16-character app password.
- Replace the SMTP Password in Jenkins with the new app password and click Test Configuration again. You should see a success:
4. Set System Admin Email Address
To customize the "From" address on outgoing alerts:
- In Manage Jenkins → Configure System, set System Admin e-mail address (e.g.,
[email protected]
). - Click Save and then Test Configuration once more.
You’ll receive another test email showing the updated From address:
5. Verify Notifications on Job Builds
- Return to the npm-version-test job and rebuild with the same
exit 1
script. - Build #10 will fail and trigger an email:
Console Output:
Started by user siddharth
...
+ exit 1
Build step 'Execute shell' marked build as failure
Sending e-mails to: [email protected]
Finished: FAILURE
You’ll receive an email titled Build failed in Jenkins: npm-version-test #10, complete with console logs and direct links:
Finally, remove the exit 1
from the build script and run again. Build #11 will succeed and send a "back to normal" message without console logs, confirming your notification pipeline is fully operational.
Links and References
Watch Video
Watch video content