Sending Slack notifications after running Github Actions

February 2, 2020

This is simply a short tip post on how to send messages to a slack channel after your github action runs. This package make this very simple. You only need to implement the following markup in your existing Github Action:

    - name: Send Slack notification
      uses: 8398a7/action-slack@v2
      if: failure()
          status: ${{ job.status }}
          author_name: ${{ }}
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Make sure you don’t forget to add the SLACK_WEBHOOK_URL secret on your repo secret settings page.

In the above snippet, the slack action will only be sent if the action fails. But, you can send on a few different conditions:

Always send the message

    if: always()

Only if the build succeeds

    if: success()

Only if the build was cancelled

    if: cancelled()

You can check more about the different bob status check functions here.