This GitHub Action sends a Slack notification with a custom message.
The action posts a message to a Slack channel. The caller is responsible for building the message string.
This action depends on:
- SonarSource/vault-action-wrapper to retrieve the Slack token from Vault
| Input | Description | Required | Default |
|---|---|---|---|
project-name |
The display name of the project; used in the Slack username. | Yes | - |
icon |
Emoji icon for the Slack message (Slack emoji code). | No | :alert: |
slack-channel |
Slack channel (without #) to post the notification into. |
Yes | - |
message |
The Slack message to send (mrkdwn format). Required when not using the deprecated jobs input. |
No | - |
color |
Slack attachment color (good, danger, warning, or a hex code). |
No | danger |
jobs |
Deprecated. A GitHub needs-like object of jobs and results. When message is not set, a failed-jobs summary is built from this input. Build the message in the caller and pass it via message instead. |
No | - |
No outputs are produced by this action.
Tip: For CI failure notifications, prefer the dedicated
notify-failureaction — it automatically includes job details, commit author, retry count, root cause analysis, and Develocity scan links without any message-building boilerplate.
jobs:
notify_on_failure:
needs: [ build, test, deploy ] # Example job dependencies
runs-on: ubuntu-latest
if: failure()
permissions:
statuses: read
id-token: write
steps:
- name: Build failure message
id: msg
if: failure()
env:
NEEDS_JSON: ${{ toJSON(needs) }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
FAILED=$(echo "$NEEDS_JSON" | jq -r 'to_entries | map(select(.value.result == "failure") | .key) | join(", ")')
DELIMITER="$(openssl rand -hex 8)"
{
echo "message<<${DELIMITER}"
printf '*Run:* <%s|View run>\n*Failed Jobs:* %s' "$RUN_URL" "$FAILED"
echo
echo "${DELIMITER}"
} >> $GITHUB_OUTPUT
- uses: SonarSource/release-github-actions/notify-slack@v1
with:
project-name: 'My Project'
slack-channel: 'engineering-alerts'
message: ${{ steps.msg.outputs.message }}- uses: SonarSource/release-github-actions/notify-slack@v1
with:
project-name: 'My Project'
slack-channel: 'team-channel'
icon: ':memo:'
color: good
message: |
*my-repo* rule metadata PR is ready for review:
https://github.com/org/my-repo/pull/42The action is a composite action that:
- Fetches
SLACK_TOKENfrom Vault pathdevelopment/kv/data/slackusingvault-action-wrapper - Uses a Python script (
notify_slack.py) with therequestslibrary to call the Slack API directly — no Docker dependency - Sets the attachment color from the
colorinput (defaults todanger) - Sets Slack username to:
<project-name> CI Notifier
- Vault policy granting access to
development/kv/data/slackmust be configured for the repository. - The secret at that path must contain a key named
token. - The Slack channel provided must exist and the token must have permission to post there.
- For failure notifications, use
if: failure()on the step or job; otherwise it will also fire on success. - Do not prefix the channel with
#. - Message formatting uses mrkdwn (Slack's markdown dialect).