Skip to content

ALJAZEERAPLUS/slack-notification-action

Repository files navigation

Slack Action

This action sends a notification of the current status of the job. The possible values for the status are: success, failure, or cancelled.

Note: You can also use this action to send a status notification based on the results of all of the Workflow jobs. Example, if a workflow has 10 jobs and 1 of them fails, then a failure message will be sent. To use this mode, you just have to define the gha_api_token and run_id parameters as explained below.

First steps, you need to set GitHub secrets for SLACK_WEBHOOK_URL that is Incoming Webhook URL. You can customize the following parameters:

Inputs variables

With Parameter Required/Optional Description
slack_webhook_url Required The Slack Incoming Webhooks URL.
Please specify the environment secret for SLACK_WEBHOOK_URL
status Optional The result of GitHub Actions job
This parameter value must contain the following word:
- success
- failure
- cancelled
default is using ${{ job.status }}
slack_channel Optional Override the default incoming Webhook Slack settings
slack_username Optional Override the default incoming Webhook Slack settings
gha_api_token Optional The Github Actions API Token to fetch all jobs statuses
run_id Optional Required if gha_api_token is set. This is the Github Actions Workflow run_id and can be found in the github.run_id environment variable
notify_all Optional If enabled it will include @here in the slack message
report_link Optional The link to the report

Usage

usage with the default incoming Webhook Slack settings,

Create the file workflow.yml in .github/workflows folder.

name: The name of your workflow
on [push]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: ./.github/github-actions/slack-action@v1
        with:
          slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
        if: always()

Scenarios

You can override the default incoming Webhook Slack settings for the channel and username, also only send notification to slack if the job failure, e.g:

Possible values are success, failure, or cancelled.

name: The name of your workflow
on [push]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: ./.github/github-actions/slack-action@v1
        with:
          slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
          slack_channel: general
          slack_username: Github
          status: failure
        if: failure()

Slack UI

Locate the Slack conversation the message was sent to and it should be waiting for you, like this:

Notification Preview

Amazing work - you've now implemented notifactions the your workflows!