Skip to main content
In this lesson, you’ll learn how to send rich, interactive Slack notifications from Jenkins pipelines using attachments and Block Kit. We will:
  • Explore Slack’s Block Kit Builder and message layouts
  • Build JSON payloads with attachments and blocks
  • Integrate payloads in Jenkins via a shared library
  • Customize messages with emojis, images, and buttons

Quick Slack Notifications Example

Out of the box, Jenkins’ Slack plugin can send basic build statuses:
These simple messages work, but to stand out you can leverage Slack’s rich layouts.

Slack API: Rich Message Layouts

Slack’s Messaging Layouts guide shows how to assemble messages with attachments and blocks:
The image shows a webpage from the Slack API documentation, specifically about creating rich message layouts. It includes navigation links on the left and content about adding blocks to messages.
Use the Slack API documentation to discover block types like section, divider, and interactive elements such as buttons and overflow menus.

Block Kit Builder

Prototype your message in Slack’s Block Kit Builder before coding.

Basic Section Block

Interactive Message with Button and Image


Constructing an Attachment Payload

Wrap blocks in an attachments array to add colors, fallbacks, or pretext:
Always validate your JSON. Slack expects arrays [] around lists and objects {} for key/value pairs.

Jenkins Slack Notification Plugin

Jenkins uses the Slack Notification Plugin to send JSON payloads. You can pass your attachment payload directly:
Table: Build Status Mapping

Shared Library: sendNotifications.groovy

Use a shared library to assemble attachments dynamically:

Custom Emojis in Slack

Add custom emojis under Customize SlackAdd Emoji. For example, upload deadpool.png as :deadpool::
The image shows a Slack interface with a pop-up window for adding a custom emoji, where an image named "deadpool.png" is being uploaded.
Ensure your team has emojis like :tada:, :warning:, and :hulk: available.

Integrating in Jenkinsfile

Call sendNotifications in your pipeline’s post section:

Resulting Slack Message

A successful pipeline produces a detailed Slack notification:
The image shows a Slack interface with a message from the Jenkins Slack App detailing a successful Kubernetes deployment pipeline. It includes information such as job name, build number, Kubernetes deployment details, and Git commit references.
This message includes:
  • A header with deployment name and emoji
  • Job name and build number fields
  • Custom icons and images
  • Optional action buttons or links to Jenkins, Kubernetes, or GitHub
Use this approach to highlight failed stages or add actionable buttons directly in Slack.

Watch Video