Slack
Provides helpers for sending Slack notifications via the Slack Web API.
Usage
yaml
include:
- project: hosst/gitlab-pipelines
file: helpers/slack.yamlVariables
| Variable | Default | Description |
|---|---|---|
SLACK_AUTHENTICATION_TOKEN | Slack Bot OAuth token — set as a masked CI/CD variable | |
SLACK_AUTHENTICATION_HEADER | Authorization: Bearer $SLACK_AUTHENTICATION_TOKEN | Authorization header |
SLACK_MESSAGE_TEXT | Hello world! | Message text |
SLACK_MESSAGE_USER | $GITLAB_USER_LOGIN | Sending user name |
SLACK_MESSAGE_CHANNEL | $CI_PROJECT_NAME | Channel to post to |
SLACK_MESSAGE_UNFURL_LINKS | false | Expand links in the message |
SLACK_MESSAGE_UNFURL_MEDIA | false | Expand media in the message |
SLACK_MESSAGE_BRANDING | by <https://gitlab.hosst.io|hosst.io> | Branding text in the context block |
SLACK_MESSAGE_BLOCKS_BRANDING | Context block appended to SLACK_MESSAGE_BLOCKS — override to customise or remove the footer branding | |
SLACK_MESSAGE_BLOCKS | Block Kit blocks (JSON) | |
SLACK_MESSAGE_ATTACHMENTS | "" | Block Kit attachments (JSON) |
SLACK_ENDPOINT_AUTH_TEST | https://slack.com/api/auth.test | Endpoint used to verify the token |
SLACK_ENDPOINT_POST_MESSAGE | https://slack.com/api/chat.postMessage | Endpoint used to post messages |
Base (.slack)
Base job using the curlimages/curl image. Extend this for custom Slack integrations.
Variables
Examples
Auth test (.slack_test)
Verifies the Slack Bot OAuth token against the auth.test endpoint.
Variables
Examples
yaml
verify-slack:
extends: .slack_testMessage (.slack_message)
Sends a Block Kit message to a Slack channel. Skips silently if SLACK_AUTHENTICATION_TOKEN is not set.
Variables
Examples
As a standalone notification job:
yaml
notify:
extends: .slack_message
variables:
SLACK_MESSAGE_CHANNEL: deployments
SLACK_MESSAGE_TEXT: "Deployed $CI_COMMIT_REF_NAME to production"Wired into an existing job's after_script via !reference so the notification fires on both success and failure:
yaml
deploy:
extends: .helm
after_script:
- export SLACK_MESSAGE_TEXT="Deployed $CI_COMMIT_REF_NAME to $ENVIRONMENT"
- !reference [.slack_message, script]