GitHub Actions Certification

Reusable Workflows and Reporting

Slack Notify GitHub Action

Integrate Slack notifications into your GitHub Actions CI/CD pipeline using the rtCamp/action-slack-notify@v2 action. This guide covers setting up a Slack Incoming Webhook, securing it as a GitHub secret, and adding a notification job that always runs.

1. Overview

The Slack Notify action sends a customizable message to your Slack channel at the end of a workflow. You provide it with environment variables for configuration:

VariableDescriptionExample
SLACK_WEBHOOKYour Slack Incoming Webhook URL (secret)${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNELChannel name or IDgeneral
SLACK_COLORAttachment color (good, #ff0000, etc.)${{ job.status }}
SLACK_ICONURL for a custom iconhttps://github.com/rtCamp.png?size=48
SLACK_MESSAGEThe notification text"Build *${{ github.workflow }}* completed"
SLACK_TITLETitle shown above the message"CI/CD Pipeline"
SLACK_USERNAMEUsername for the Slack botrtCamp

Here’s a minimal step configuration:

- name: Slack Notification
  uses: rtCamp/action-slack-notify@v2
  env:
    SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
    SLACK_CHANNEL: general
    SLACK_COLOR: ${{ job.status }}
    SLACK_ICON: https://github.com/rtCamp.png?size=48
    SLACK_MESSAGE: "Build *${{ github.workflow }}* completed"
    SLACK_TITLE: "CI/CD Pipeline"
    SLACK_USERNAME: rtCamp

2. Create a Slack Channel & Webhook

  1. In Slack, create a new channel (e.g., github-actions-channel).
  2. Visit Incoming Webhooks in the Slack API and click Create an AppFrom scratch.
  3. Enable Incoming Webhooks and add to your channel.

The image shows the Slack API settings page for building apps, featuring options like Incoming Webhooks, Interactive Components, and Slash Commands. The sidebar lists various settings and features available for app configuration.

  1. Select your channel; Slack generates a Webhook URL. Test it with:
curl -X POST -H 'Content-type: application/json' \
  --data '{"text":"Hello, World!"}' YOUR_WEBHOOK_URL_HERE

The image shows a Slack authorization page where the GitHub Actions application is requesting permission to access the "mcd-level2" Slack workspace, with a dropdown menu to select a channel for posting.

3. Store the Webhook as a GitHub Secret

  1. Navigate to your repo’s Settings → Secrets and variables → Actions.
  2. Click New repository secret and add:
    • Name: SLACK_WEBHOOK
    • Value: <your-slack-webhook-url>

Warning

Keep your Webhook URL confidential. Anyone with this URL can post messages to your Slack channel.

The image shows a GitHub repository settings page, specifically the "Secrets and variables" section, displaying environment and repository secrets like AWS keys and passwords.

The image shows a GitHub repository settings page, specifically the "Secrets and variables" section under "Actions," listing various environment and repository secrets.

4. Add the Slack Notification Job

Append this job to your workflow file (e.g., .github/workflows/solar-system.yml). It uses if: always() so it runs regardless of success, failure, or cancellation, and continue-on-error: true to avoid blocking the pipeline.

jobs:
  # ... other jobs ...

  slack-notification:
    if: always()
    name: Slack Notification
    needs: [dev-integration-testing, prod-integration-testing]
    continue-on-error: true
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Send Slack notification
        uses: rtCamp/action-slack-notify@v2
        env:
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
          SLACK_CHANNEL: github-actions-channel
          SLACK_COLOR: ${{ job.status }}
          SLACK_ICON: https://gitlab.com/sidd-harth/solar-system/-/raw/main/images/saturn.png
          SLACK_MESSAGE: ":hammer_and_wrench: Triggered by ${{ github.actor }}"
          SLACK_TITLE: "Pipeline Status"

Once pushed, your workflow graph will include the new notification job:

The image shows a GitHub Actions workflow interface with a workflow named "Solar System" in progress, displaying job statuses and a visual representation of the workflow steps.

After completion, you’ll see its result in the summary:

The image shows a GitHub Actions workflow summary for a project, indicating a successful run with various jobs like unit testing, code coverage, and Slack notification.

5. Verify always() Behavior

Even if the workflow is canceled or fails, the Slack notification runs because of if: always():

The image shows a GitHub Docs page about GitHub Actions expressions, specifically focusing on the "always" and "cancelled" expressions, with examples and a warning about using "always."


With this setup, every GitHub Actions run—successful, failed, or canceled—triggers a Slack notification, keeping your team informed in real time.

Watch Video

Watch video content

Previous
Uploading Reports to AWS S3 Storage