Integrating Jenkins with Slack and Email Notification

Monday, January 27, 2020

Integrating Jenkins with Slack and Email Notification


Continuous Integration is a process in which all development work is integrated as early as possible, with the resulting artefacts automatically built and tested. This blog walks through integrating Jenkins with Slack and email notifications, so your team is notified of every build on a Slack channel, and you get an email whenever a build fails.

Jenkins CI with Slack and email notification
Jenkins CI with Slack and Email Notification

The below topics are covered in this blog -

1) Introduction to Jenkins continuous integration
2) Creating a Slack account and incoming webhook
3) Configuring the Slack Notification plugin in Jenkins
4) Configuring email notification in Jenkins
5) Testing the setup

1. Introduction

Jenkins is an open-source continuous integration tool written in Java, used for building, testing, and reporting on isolated changes in a larger codebase in real time. It lets developers find defects and fix them rapidly through automated testing.

2. Create a Slack Account and Incoming Webhook

Slack is a chat platform that provides incoming webhooks, which let external systems post messages into a channel. We will use one so Jenkins can send build notifications into your Slack channel.

If you haven't created your Slack account yet, sign up first, then visit:

https://slack.com/signin?redir=/apps/manage

Or: Channel Administrator -> Manage Apps -> Create Incoming Webhooks

Once you have an account, go to Slack → Administration → Manage Apps.

Slack Manage Apps screen
Slack Manage Apps

Search for Incoming WebHooks:

Searching for Incoming WebHooks in the Slack app directory
Search for Incoming WebHooks

You will get the screen below:

Slack Incoming WebHooks app page
Incoming WebHooks

Click Add to Slack and select the channel you want build notifications posted to:

Selecting the Slack channel for the incoming webhook
Select Channel Name

Click Add Incoming WebHook Integration. You will get a Slack webhook URL that looks like this:

https://hooks.slack.com/services/TXXXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX

Treat this URL as a secret. Anyone who has it can post messages into your channel. Never commit it to a repository, paste it in a screenshot, or publish it.

You can test it with a curl command:

curl -X POST --data-urlencode \
  'payload={"channel": "#codeztech-jenkins", "username": "webhookbot",
   "text": "This is posted to #codeztech-jenkins from a bot named webhookbot.",
   "icon_emoji": ":ghost:"}' \
  https://hooks.slack.com/services/TXXXXXXXX/BXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX
Slack incoming webhook URL configuration screen
Slack Webhook URL

3. Configure the Slack Notification Plugin in Jenkins

Make sure the Slack Notification plugin is installed from Manage Jenkins → Manage Plugins. You can download it directly from:

https://updates.jenkins.io/download/plugins/slack/

Then go to Manage Jenkins → Upload Plugin and restart Jenkins. I have made a full video on this, linked at the bottom of this post. Feel free to comment on my YouTube channel or here if you run into any issue.

Once restarted, go to Manage Jenkins → Configure System and scroll to the Slack section.

Base URL        https://hooks.slack.com/services/
Team Subdomain  your Slack workspace subdomain
Credential      the webhook token, stored as a Jenkins secret
Channel         #your-channel-name

You can find the team subdomain in your Slack URL path:

Finding the Slack team subdomain for the incoming webhook
Slack - Incoming WebHook Team Subdomain

Add the credential and enter your channel name prefixed with # — the channel where you want all build notifications sent. Click Test Connection to confirm the setup works.

Configuring Slack notification settings in Jenkins
Configure Slack on Jenkins

4. Configure Email Notification in Jenkins

To configure email notification in Jenkins, go to Manage Jenkins → Configure System → E-mail Notification and use the following settings:

SMTP Server           smtp.gmail.com
Default user e-mail   your-address@gmail.com
SMTP Authentication   checked
Username              your-address@gmail.com
Password              your app password (see below)
Use SSL               checked
SMTP Port             465
Reply-To Address      an alternate address

Do not use your normal Gmail password — Google will reject it. Generate an app password instead:

Step 1 — Sign in to Gmail and go to Manage your Google Account
Step 2 — Open the Security tab and find the sign-in section
Step 3 — Click App passwords and select the device or app
Step 4 — Generate the password and copy it

Paste that app password into the Jenkins password field, then click Test configuration to send a test email.

Configuring email notification settings in Jenkins
Configure Email Notification on Jenkins

5. Video Walkthrough


About the Author
Atique Ahmed — Principal AI Architect. 7x Microsoft MVP and Guinness World Record holder for Programming Excellence. Founder of Codez Tech.
Portfolio  |  LinkedIn  |  GitHub

6 comments :

Dwayne said...

Your work is truly appreciated. The material gives lots of innovative ideas which is beneficial to our knowledge. Bulk Mailing Services

Pooja Sharma said...
This comment has been removed by the author.
Unknown said...

can u make other tutorial how to get aproval email for deploy

Pigiga said...

Browsing MaltaMagazine, I was amazed at its ability to present complex global news and local business trends in a clear and engaging way, making it a go-to platform for staying informed.

Pigiga said...

RomaniaMagazine continues to impress with its in-depth coverage of Romanian news, technology trends, business updates, and sports, presenting each topic with clarity and a commitment to journalistic integrity that readers truly appreciate.

Pigiga said...

I always look forward to the latest updates from TechyFreak, as it provides in-depth insights on emerging technology trends, detailed product reviews, and useful tutorials that make staying ahead in the digital world much easier.