GitHub Actions Notifications

A pipeline that fails silently wastes everyone's time. Notifications put the result in front of the right people at the right moment. GitHub offers built-in alerts, and workflows can send custom messages to chat tools.

Notifications in Simple Words

A smoke detector does not fix a fire. It tells you early, so you can act. Workflow notifications play the same role for broken builds. They announce the problem and link to the exact log.

Built-In GitHub Notifications

GitHub sends alerts about workflow runs without any extra code. Open your profile, choose Settings, then Notifications, and find the Actions section. Choose email, the web inbox, or the GitHub Mobile app. A common setup sends only failed runs for workflows that you triggered.

Status Badges

A badge shows the latest result on your README page. Open a workflow in the Actions tab, select the three-dot menu, and choose Create status badge. GitHub generates Markdown that looks like this.

![CI](https://github.com/OWNER/REPO/actions/workflows/ci.yml/badge.svg)

The badge turns green when the last run passes and red when it fails.

Notification Flow

+----------+     +---------+     +----------------+     +-----------------+
| Workflow | --> | Job     | --> | Notify step    | --> | Chat channel or |
| starts   |     | fails   |     | if: failure()  |     | email           |
+----------+     +---------+     +----------------+     +-----------------+

Run a Step Only When Something Fails

Status functions control when a step executes. The failure() function returns true when any earlier step failed. The success() function returns true when all earlier steps passed. The always() function runs the step no matter what.

Send a Slack Message With curl

Slack provides incoming webhooks. A webhook is a private web address that accepts messages. Create one in your Slack workspace, then store the address as a repository secret named SLACK_WEBHOOK_URL.

name: CI With Alerts

on:
  push:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: npm test

      - name: Alert on failure
        if: failure()
        env:
          WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
        run: |
          curl -X POST -H "Content-type: application/json" \
            --data "{\"text\":\"Build failed on ${{ github.repository }} (${{ github.ref_name }}). Details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}" \
            "$WEBHOOK"

The message includes the repository, branch, and a direct link to the run. Readers jump straight to the logs.

A Separate Notification Job

A dedicated job reports on the result of several jobs together.

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - run: npm test

  notify:
    needs: test
    if: always()
    runs-on: ubuntu-latest
    steps:
      - run: echo "Test result is ${{ needs.test.result }}"
test job ---> notify job (always runs)
                 reads needs.test.result
                 = success | failure | cancelled | skipped

Other Channels

ChannelMethod
Microsoft TeamsIncoming webhook with a JSON message
DiscordWebhook address with a content field
EmailA mail-sending action with SMTP secrets
GitHub issueThe GitHub CLI or github-script action

Writing Useful Messages

  • Name the repository and branch.
  • Link to the failed run.
  • Include the commit author when it helps the right person respond.
  • Send alerts on failures only. Constant success messages train people to ignore the channel.

Protect the Webhook

Anyone holding a webhook address can post to your channel. Store it as a secret and never print it in logs. Rotate the address in Slack when you suspect a leak.