Chetan Talwar
Tech Talks by Chetan Talwar

Tech Talks by Chetan Talwar

Github Actions - Sending Notifications to Slack

Github Actions - Sending Notifications to Slack

Chetan Talwar's photo
Chetan Talwar
·Sep 29, 2021·

2 min read

Subscribe to my newsletter and never miss my upcoming articles

This is about sending notifications to Slack Channel via using Github Actions pipeline.

Link to Github Market Place -> Github Action

Usage

  • In the below stated example, separate job for Notifications has been created which will send the notification to the SLACK CHANNEL irrespective of the build job status.
  • Message to be sent can be customised as per the need, you can include other properties as well using Github Contexts.
  • In order to use this, all you need is to create a Web-hook in your Slack Channel, follow this link for info about creating a one.
  • Once you have created the web-hook, just add the Web-hook Address in secrets and utilise in your Action File in this manner ${{ secrets.SECRET_NAME }}.

Usage

  • In the below stated example, separate job for Notifications has been created which will send the notification to the SLACK CHANNEL irrespective of the build job status.
  • Message to be sent can be customised as per the need, you can include other properties as well using Github Contexts.
  • In order to use this, all you need is to create a Web-hook in your Slack Channel, follow this link for info about creating a one.
  • Once you have created the web-hook, just add the Web-hook Address in secrets and utilise in your Action File in this manner ${{ secrets.SECRET_NAME }}.
  • Sample Usage

      name: Pipeline Name
    
      on:
      push:
          branches: [ branch_name ]
      pull_request:
          branches: [ branch_name ]
      jobs:
    
      build:
          runs-on: ubuntu-latest
          steps:
          - name: Demo Step
            run: docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$GITHUB_RUN_NUMBER
      notify:
          runs-on: ubuntu-latest
          if: always()
          needs: build
          steps:
          - name: Send a Notification
              id: notify
              uses: thechetantalwar/slack-notify@v2
              with:
              slack_webhook_url: ${{ secrets.SLACK_HOOK }}
              message: "Github Action Build Number ${{ github.run_number }} Completed for ${{ github.repository }} and the outcome is  ${{ needs.build.result }}."
    
  • The above stated sample will send a message like below Sample Notification

License: MIT