Skip to content

sonots/slack-notice-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Slack Notice Action

codecov

Yet Another GitHub Action to notify slack.

Quick Start

- uses: sonots/slack-notice-action@v3
  with:
    status: ${{ job.status }}
    only_mention_fail: 'channel'
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Required, but this should be automatically supplied by GitHub.
    SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # Required. Legacy Incoming Webhook is also supported.
  if: always() # Pick up events even if the job fails or is canceled.

success

Usage

with Parameters

key value default description
status success or failure or cancelled or custom '' Use ${{ job.status }}.
text any string '' text field
text_on_success any string '' text field on success
text_on_fail any string '' text field on failure
text_on_cancel any string '' text field on cancellation
title any string workflow name title field
mention here or channel or user_id such as user_id,user_id2 '' Mention always if specified. The user ID should be an ID, such as @U024BE7LH. See Mentioning Users
only_mention_fail here or channel or user_id such as user_id,user_id2 '' Mention only on failure if specified

Supported by only legacy incoming webhook.

key value default description
username '' override the legacy integration's default name.
icon_emoji '' an emoji code string to use in place of the default icon.
icon_url '' an icon image URL string to use in place of the default icon.
channel '' override the legacy integration's default channel. This should be an ID, such as C8UJ12P4P.

Custom notification. See Custom Notification for details.

key value default description
payload '' Only available when status: custom. The payload format can pass javascript object.

Example

Legacy Incoming Webhook Example:

- uses: sonots/slack-notice-action@v3
  with:
    status: ${{ job.status }}
    username: Custom Username
    icon_emoji: ':octocat:'
    channel: 'C8UJ12P4P'
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Required, but this should be automatically supplied by GitHub.
    SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # Required. Legacy Incoming Webhook is also supported.
  if: always() # Pick up events even if the job fails or is canceled.

In case of success:

success

In case of failure:

failure

In case of cancellation:

canceled

Example: Custom Notification

Use status: custom if you want to send an arbitrary payload. The payload format can pass javascript object.

- uses: sonots/slack-notice-action@v3
  with:
    status: custom
    payload: |
      {
        text: "Custom Field Check",
        attachments: [{
          "author_name": "sonots@slack-notice-action", // json
          fallback: 'fallback',
          color: 'good',
          title: 'CI Result',
          text: 'Succeeded',
          fields: [{
            title: 'lower case',
            value: 'LOWER CASE CHECK'.toLowerCase(),
            short: true
          },
          {
            title: 'reverse',
            value: 'gnirts esrever'.split('').reverse().join(''),
            short: true
          },
          {
            title: 'long title1',
            value: 'long value1',
            short: false
          }],
          actions: [{
          }]
        }]
      }
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # optional
    SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required

See also:

Special Thanks

This orginally started as a fork of https://github.com/8398a7/action-slack. Thanks!