Add Slack notifications into Github Actions

Add Slack notifications into Github Actions

🎯Workflow

1️⃣Search🔍 the Slack-Notifications in the marketplace🛒
2️⃣Configure📋 the Webhook
3️⃣Configure📋 the Job

1️⃣Search🔍 the Slack-Notifications in the marketplace🛒

Go to github action marketplace

Select Slack-Notify🔔
Read📖 the doc

2️⃣ Configure 📋 the Webhook

For communication between Slack and Github we need a Slack webhook.

Login in Slack
Enter here to add the incoming webhook

You will be asked❓ to enter your team URL
Select the channel📱 to which you want to post
Save the URL generated as a Webhook

3️⃣Configure📋 the Job

Add ➕ a Slack Notification Job to the pipeline

Slack-Notify:
runs-on: ubuntu-latest
#Wait for test job ending
needs: test
#If the test job is wrong, this job will still be executed
if: always()
steps:
– uses: actions/checkout@v2
– name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
#Settings->Secrets & Variables->Actions->New Secret
#Paste here your secret webhook
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
# The variable needs.test.result print the result of the test job
SLACK_COLOR: ${{ needs.test.result }}
SLACK_CHANNEL: general
SLACK_USERNAME: ‘Node-Bot’
SLACK_TITLE: Workflow ${{ needs.test.result }}
SLACK_MESSAGE_ON_SUCCESS: ‘✅’
SLACK_MESSAGE_ON_FAILURE: ‘❌’
SLACK_FOOTER: By Sharker3312

🚨🚨🚨:It is likely that you only want to send notifications when an error occurs, in this case just substitute this line
if: ${{ always() && (needs.failing-job.result == ‘failure’ || needs.failing-job.result == ‘timed_out’) }}

Done✅🚀

Leave a Reply

Your email address will not be published. Required fields are marked *