Skip to main content
← Back to workflows

How to Send Slack Notifications from GitHub Actions

8398a7-action-slack -
GitHub Action
Release v3.16.2
GitHub Org's stars
Contributors
CICube banner
The GitHub Actions dashboard helps you spot bottlenecks and optimize your CI pipeline with actionable insights.
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

Monitoring GitHub Actions Workflows

CICube is a GitHub Actions monitoring tool that provides you with detailed insights into your workflows to further optimize your CI/CD pipeline. With CICube, you will be able to track your workflow runs, understand where the bottlenecks are, and tease out the best from your build times. Go to cicube.io now and create a free account to better optimize your GitHub Actions workflows!

CICube GitHub Actions Workflow Duration Monitoring