DevSecOps - Kubernetes DevOps & Security
Kubernetes Operations and Security
Demo Slack Jenkins Custom App
In this guide, you’ll learn how to send rich, interactive Slack notifications from Jenkins using attachments, custom emojis, and buttons. We’ll walk through:
- Creating a custom Slack App & bot user
- Assigning OAuth scopes for attachments and emojis
- Generating and storing an OAuth token in Jenkins
- Configuring the Slack plugin in Jenkins
- Testing notifications and troubleshooting common issues
By the end, your Jenkins pipelines can post build status, Git details, Kubernetes metadata, and clickable actions—all with custom formatting.
Prerequisites: Slack Notification Plugin
Note
Make sure the Slack Notification Plugin is installed in your Jenkins instance. It provides the slackSend
step with support for attachments and Block Kit layouts.
To start, send a simple text notification:
slackSend color: 'good', message: 'Hello from Jenkins Pipeline!'
Adding Attachments
Define an attachments array to include richer content:
def attachments = [
[
text: 'I find your lack of faith disturbing!',
fallback: 'Vader is upset.',
color: '#ff0000'
]
]
slackSend(channel: '#general', attachments: attachments)
Attachments require a bot user in Slack. Let’s create one next.
1. Create a Slack App
Open the Slack API dashboard:
https://api.slack.com/appsClick Create an App and choose From scratch.
Enter a name (e.g., Jenkins Slack App) and select your workspace.
Optionally, customize the app’s icon and description:
2. Assign Bot OAuth Scopes
In your app settings, go to OAuth & Permissions → Bot Token Scopes. Add the following:
Scope | Purpose |
---|---|
files:write | Upload and manage files |
chat:write | Post messages in channels & direct messages |
chat:write.customize | Use attachments and interactive elements |
emoji:read | List custom emojis |
reactions:write | Add or remove reactions |
Scroll up and click Install to Workspace, then authorize. Copy the Bot User OAuth Token from the dashboard:
3. Configure Jenkins
- In Jenkins, navigate to Manage Jenkins → Configure System.
- Find the Slack section.
- Under Credentials, click Add → Jenkins → Secret text.
- Paste your Bot User OAuth Token and give it an ID (e.g.,
slack-bot-token
).
- Back in the Slack section, set:
- Team Domain: your-workspace
- Integration Token Credential: select your secret text
- Default Channel:
#jenkins
Test the Connection
Click Test Connection.
Warning
If you receive {"ok":false,"error":"not_in_channel"}
, the bot hasn’t been invited to your channel yet.
Invite the bot in Slack:
Once invited, re-run Test Connection—you should see a success message.
Next Steps
- Explore Slack Block Kit for advanced layouts: Block Kit Builder
- Use interactive buttons and menus in your pipeline notifications
- Integrate job logs, Git diff summaries, or Kubernetes pod links
Links and References
- Slack API: Apps
- Slack OAuth Scopes
- Jenkins Slack Notification Plugin
- Jenkins Pipeline Syntax
- Slack Block Kit Documentation
Watch Video
Watch video content