name: 'Usage of action-slack-notify GitHub Action'
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
Slack Notify
GitHub Action for sending a notification to a Slack channel
What is action-slack-notify?
Staying updated with real-time notifications can greatly enhance our workflow management, especially when coordinating across different platforms. The Slack Notify GitHub Action is an active and stable tool that allows us to send custom messages directly to a Slack channel from our GitHub Actions workflows. This is particularly useful for keeping the team informed about deployment statuses, test results, or any critical workflow events.
How to Customize the Slack Username
Set a custom username for the bot sending the Slack messages.
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_USERNAME: "Your Custom Bot Name"
How to Set the Slack Message Author
Define the GitHub username of the person who triggered the action.
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_MSG_AUTHOR: "specific-username"
How to Customize the Slack Icon URL
Use a specific URL for the user/bot icon displayed in the Slack message.
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_ICON: "http://url-to-your-icon.png"
How to Use Slack Emoji as Icon
Set a Slack emoji as the icon for messages instead of using a URL.
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_ICON_EMOJI: ":bell:"
How to Set Slack Message Color
Customize the color of the vertical line on the left side of Slack messages based on job status.
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_COLOR: "${{ job.status }}"
How to Enable Name Mentioning in Messages
Allow mentions in Slack messages by setting usernames as links.
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_LINK_NAMES: 'true'
How to Customize the Main Slack Message
Override the default Slack message generated from the git commit message.
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_MESSAGE: "Your custom message here"
How to Set the Slack Message Title
Define a custom title for the Slack message.
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_TITLE: "Deployment Status"
How to Customize the Slack Message Footer
Modify the footer of the Slack message.
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_FOOTER: "Custom footer text"
How to Send Minimal Slack Messages
Send more concise messages by removing certain elements.
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
MSG_MINIMAL: "ref,actions url"
How to Convert Markdown to Slack Formatting
Automatically convert markdown syntax to Slack formatting.
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACKIFY_MARKDOWN: 'true'
How to Reply to a Specific Slack Message (Thread)
Send a message as a reply in a specific thread by specifying the parent message timestamp.
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_THREAD_TS: '1586130833.000100'
How to Use a Slack Token for Authentication
Authenticate the message sending using a Slack bot token instead of a webhook URL.
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_CHANNEL: "your-channel-id"
How to Customize Messages Based on Job Status
Send specific messages depending on the job’s success, failure, or cancellation.
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_MESSAGE_ON_SUCCESS: "Deployment succeeded!"
SLACK_MESSAGE_ON_FAILURE: "Deployment failed!"
SLACK_MESSAGE_ON_CANCEL: "Deployment cancelled!"
How to Send a Custom JSON Payload to Slack
Override all other variables and send a custom JSON payload directly to Slack.
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CUSTOM_PAYLOAD: '{"text": "Custom message"}'
How to Upload a File to Slack
Attach a file to your Slack message.
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_FILE_UPLOAD: "/path/to/your/file.txt"
How to Enable Escape Sequences in Messages
Allow backslash escape sequences such as \n (new line) and \t (tab) in your custom messages.
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
ENABLE_ESCAPES: 'true'