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.
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.