Send messages to Slack from GitHub Actions.
This action sends message to Slack during your GitHub Actions workflow. It takes a minimalist approach, showing a handful of metadata options like repository, branch & commit. You can optionally update message in-place to reduce noise in your Slack channel.
- uses: someimportantcompany/github-actions-slack-message@v1
with:
channel: ${{ env.SLACK_CHANNEL }}
bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
text: Firing a bot-token message
- uses: someimportantcompany/github-actions-slack-message@v1
with:
webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
text: Firing a webhook message
- Including a
color
wraps your message in a (soon to be deprecated)attachments
block. - Links refer back to your repository, the branch & the commit.
If you are planning to send multiple Slack messages per invocation, and you'd prefer to update a single message instead of posting multiple messages, you can pass the first Slack message's message-id
to future calls, thus updating in place. A bot-token
is required to update messages.
- uses: someimportantcompany/github-actions-slack-message@v1
id: slack
with:
channel: ${{ env.SLACK_CHANNEL }}
bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
text: Deployment started
- run: npm run deploy
- uses: someimportantcompany/github-actions-slack-message@v1
with:
channel: ${{ env.SLACK_CHANNEL }}
bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
text: Deployment finished
color: good
message-id: ${{ steps.slack.outputs.message-id }}
Alongside the Slack default colors good
, warning
& danger
, this action supports some additional colors for convenience:
Key | Value |
---|---|
success |
good |
failure |
danger |
info |
|
gray |
|
grey |
|
orange |
|
purple |
- uses: someimportantcompany/github-actions-slack-message@v1
with:
webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
text: Build finished
color: good # Slack already-supported color
- uses: someimportantcompany/github-actions-slack-message@v1
with:
webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
text: Build failed
color: failed # Aliased color
Using built-in Actions conditionals, you can send an error if the job succeeded or failed.
- uses: someimportantcompany/github-actions-slack-message@v1
if: success()
with:
webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
text: Build passed
color: success
- uses: someimportantcompany/github-actions-slack-message@v1
if: failure()
with:
webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
text: Build failed
color: failure
Key | Description |
---|---|
text |
Required. The text to send to Slack, see Slack's documentation for formatting. |
color |
Specify the color of the Slack attachment. |
bot-token |
Required if webhook-url was not provided - a Slack bot token to send messages with. |
webhook-url |
Required if bot-token was not provided - a Slack webhook URL to send messages to. |
channel |
A channel to send messages to - required if bot-token was provided. |
message-id |
The ID of the existing Slack message to update - only valid if bot-token was provided. |
title |
The title of the Slack message, optional. |
image-url |
The image URL for attachment |
thumb-url |
The thumb URL for attachment |
Key | Description |
---|---|
message-id |
The ID of the message sent to Slack - pass to the message-id input to update. |
To use this GitHub Action with your Slack workspace, you'll need a Slack bot token or Slack webhook URL, both can be generated by making a Slack app.