DEV Community

Cover image for Add Slack notifications into Github Actions
Lester Diaz Perez
Lester Diaz Perez

Posted on

Add Slack notifications into Github Actions

Image description

🎯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🛒

Image description

  • Select Slack-Notify🔔
  • Read📖 the doc

2️⃣ Configure 📋 the Webhook

Image description

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


Enter fullscreen mode Exit fullscreen mode

🚨🚨🚨: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✅🚀

Image description

Top comments (0)