Skip to content
message-square

GitHub Action

Slack Message

v1.5.0 Latest version

Slack Message

message-square

Slack Message

Send messages to Slack from GitHub Actions

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Slack Message

uses: someimportantcompany/[email protected]

Learn more about this action in someimportantcompany/github-actions-slack-message

Choose a version

Slack Message

GitHub CICD Coverage

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.

Usage

- 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

Individual messages

  • Including a color wraps your message in a (soon to be deprecated) attachments block.
  • Links refer back to your repository, the branch & the commit.

Updating an existing message

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 }}

Updating message

Additional colors

Alongside the Slack default colors good, warning & danger, this action supports some additional colors for convenience:

Key Value
success good
failure danger
info #17a2b8
gray #B6B6B6
grey #B6B6B6
orange #FF4500
purple #9400D3
- 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

Running if-success or if-failure

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

Inputs

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

Outputs

Key Description
message-id The ID of the message sent to Slack - pass to the message-id input to update.

Setup

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.