Send Slack notification when Github Actions fails

Ravgeet Dhillon
Ravgeet Dhillon on Sep 13, 20203 min read
Written in
Blog banner for Send Slack notification when Github Actions fails

We must be sure that if you and your team use Github, then you must using Github Actions as well. When 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 we are working in a team, we need a better way to monitor our Github Actions. We need to know the status of our Github Actions specifically when they fail so that our development team can act upon them as quickly as possible.

We faced this issue often at our workspace. So our team decided to publish a new Github Action that can be used effectively to notify our Slack channel whenever our Github Action fails.

Contents

1. Get a Webhook URL

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

2. Use notify-slack-action

We assume that we already have a Github Action that fails often and we need to monitor it. Add the above the following step in the Github Action workflow:

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

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

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

Results

We will fail our Github Action deliberately to test our Github Actions monitoring.

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

Alright! We can see that a notification message was sent to our Slack channel stating the commit and repository it failed in. This is extremely useful when we have multiple projects using Github Actions and we want to keep a check on our Github Actions workflow.

We strongly feel that this action will increase the productivity of any team at any workspace. If you any doubts or appreciation for our team, let us know in the comments below.

Subscribe to RavSam Web Solutions newletter for information about Website development, mobile apps development and software development

Loved this post? Join our Newsletter 🚀

We write about Nuxt, 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, Freelancer and Developer at RavSam. He helps startups, businesses, open-source organizations with Digital Product Development. He is a fan of Jamstack and likes to work with Flutter, Strapi, Nuxt/Vue and Python. Connect with Ravgeet on Twitter and LinkedIn.

KEEP READING

Blog banner for Script as a Task using VS Code IDE

Script as a Task using VS Code IDE

Written in Automation
Blog banner for Deploy a Serverless Probot/Github App on Netlify Functions

Deploy a Serverless Probot/Github App on Netlify Functions

Written in Automation

Got a project or partnership in mind?

Let's Talk

Contact Us ->