Monitor your Github Actions status by sending success or failure notifications to your Slack channel.

Send Slack Notifications when Github Action fails

Ravgeet Dhillon

Ravgeet Dhillon

Written on Sep 13, 2020 in Automation

⏱ 4 min read

Blog banner for Send Slack Notifications when Github Action fails

If you and your team use Github, then you must be using Github Actions as well. Whenever a Github Action fails, Github automatically sends you an email regarding the event. It works only if you are working on an individual project. However, when you are working in a team, you need a better way to monitor your Github Actions. You need to know the status of your Github Actions specifically when they fail so that your engineering team can act upon them as quickly as possible.

In this blog, you’ll learn to send a notification to your Slack channel whenever your Github Action fails. To solve this issue, you’ll use the notify-slack-action published by us.

Contents

Getting a Webhook URL

To send notifications to your Slack channel, you need to create a Slack App. You can follow this easy tutorial that includes tips to create your own Slack App and get a webhook URL. Once you have a webhook URL, you need to add it to the Github Actions secrets with the name - ACTION_MONITORING_SLACK

Using notify-slack-action

Let’s assume that you already have a Github Action that fails often and you need to monitor it. Add the following step as the last step in your Github Action workflow:

- name: Report Status
  if: always()
  uses: ravsamhq/notify-slack-action@v1
  with:
    status: ${{ job.status }}
    notify_when: 'failure'
  env:
    SLACK_WEBHOOK_URL: ${{ secrets.ACTION_MONITORING_SLACK }}

Besides the inputs given above, you can provide plenty of inputs to the notify-slack-action and make your notification more informative.

status: ${{ job.status }} # required
notify_when: 'failure'
notification_title: '{workflow} has {status_message}'
message_format: '{emoji} *{workflow}* {status_message} in <{repo_url}|{repo}>'
footer: 'Linked to Repo <{repo_url}|{repo}>'
notify_when: 'failure'
mention_users: 'U0160UUNH8S,U0080UUAA9N'
mention_users_when: 'failure,warnings'
mention_groups: 'SAZ94GDB8'
mention_groups_when: 'failure,warnings'

You can find and read more about the action at Github Marketplace.

This is all you need to monitor your Github Actions workflow. If you want to monitor each run of your Github Action workflow even when it succeeds, you can simply change the notify_when parameter value to success,failure,warnings.

Results

Open your Github Action and fail it deliberately to test your Github Actions monitoring.

Failed Github Actions run
Failure in Github Action
Failure notification in Slack
Failure notification recieved in Slack

Alright! You can see that a notification message was sent to the Slack channel stating the commit and repository it failed in.

This is extremely useful when you have multiple projects using Github Actions and you want to keep a check on your Github Actions workflow. I strongly feel that this action will increase the productivity of any team at any workspace.

📫

Loved this post? Join our Newsletter.

We write about React, Vue, Flutter, Strapi, Python and Automation. We don't spam.

Please add a valid email.
By clicking submit button, you agree to our privacy policy.
Thanks for subscribing to our newsletter.
There was some problem while registering your newsletter subscription. Please try again after some time or notify the owners at info@ravsam.in

ABOUT AUTHOR

Ravgeet Dhillon

Ravgeet is a Co-Founder and Developer at RavSam. He helps startups, businesses, open-source organizations with Digital Product Development and Technical Content Writing. He is a fan of Jamstack and likes to work with React, Vue, Flutter, Strapi, Node, Laravel and Python. He loves to play outdoor sports and cycles every day.

Got a project or partnership in mind?

Let's Talk

Contact Us ->