💸Save up to $132K/month in CI costs!👉 Try Free
Skip to main content
← Back to workflows

How to Send Slack Notifications from GitHub Actions

8398a7-action-slack -
GitHub Action
Release v3.16.2
584
Contributors
Contributor - 8398a7Contributor - technote-space

Optimize Your CI/CD Pipeline

Get instant insights into your CI/CD performance and costs. Reduce build times by up to 45% and save on infrastructure costs.

45% Faster Builds
60% Cost Reduction
Usage
name: 'Usage of action-slack GitHub Action'
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took,pullRequest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
if: always() # Pick up events even if the job fails or is canceled.

action-slack logo

action-slack

This action sends customizable Slack notifications based on the status of GitHub Actions jobs, with support for GitHub Enterprise and custom formats.


What is action-slack?

The action-slack GitHub Action allows you to send notifications to a Slack channel about the status of your GitHub Actions jobs. It supports both standard job statuses (success, failure) and custom notification formats, and it can be integrated with GitHub Enterprise (GHE).

How to Send Slack Notifications for All Job Statuses

To send notifications regardless of job success or failure, use the if: always() condition and provide the Slack webhook URL:

with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took,pullRequest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

The fields input allows you to select the information included in the notification.

How to Customize Slack Notifications

You can customize the notification format by using the custom_payload input. This example customizes the Slack message based on the job's success or failure:

with:
status: custom
fields: workflow,job,commit,repo,ref,author,took
custom_payload: |
{
attachments: [{
color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning',
text: `${process.env.AS_WORKFLOW}\n${process.env.AS_JOB} (${process.env.AS_COMMIT}) of ${process.env.AS_REPO}@${process.env.AS_REF} by ${process.env.AS_AUTHOR} ${{ job.status }} in ${process.env.AS_TOOK}`,
}]
}

The custom_payload option allows you to fully control the message content using Slack's message formatting.

How to Use action-slack with GitHub Enterprise

To integrate action-slack with GitHub Enterprise (GHE), specify your GHE base URL using the github_base_url input:

with:
github_base_url: https://your.ghe.com
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took,pullRequest

How to Set Required Permissions

If your GitHub Actions workflow explicitly defines permissions, ensure that the following permissions are granted for action-slack to work:

permissions:
contents: read
actions: read