A simple Slack message sender for GitHub Actions
933
This Action enables sending Slack messages to incoming webhook endpoints.
It works by taking in escaped JSON that is formatted for Slack's message API and send a request to the endpoint specified by environment variables.

action "Notify" {
needs = ["Filter For Tags"]
uses = "jwinton/slack-github-action"
args = ["{\"text\":\"The tag [BRANCH_OR_TAG] was just pushed!\"}"]
env = {
SLACK_PATH = "/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
}
}
For some basic JSON examples see the examples page.

Only one environment variable is required:
SLACK_PATH: should be set to the path of your Slack Incoming Webhook.
https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX then the path will be /services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX. Be sure to include the slash at the beginningWhen constructing your message your can use environment variables in your message by wrapping a value in brackets. If an environement variable called FOO is set, your message can include [FOO] and it will be interpolated into the message. For example:
{
"text": "This message is so show that environment variable FOO is set to: [FOO]"
}
This is handy for pulling in default environment variables provided by GitHub as well as passing in your own!
As a way to make things easier a convenience environment variable called BRANCH_OR_TAG is added to the container. It is simply the name of the branch or value of a tag as defined by the default $GITHUB_REF environment variable. Combined with filters it can be a nice for certain messages.
A simple notification for a push of a tag to a repo follows:
workflow "Test!" {
on = "push"
resolves = ["Send Message"]
}
# Filter for master branch
action "Filter For Tags" {
uses = "actions/bin/filter@master"
args = "tag v*"
}
action "Send Message" {
needs = ["Filter For Tags"]
uses = "docker://jwinton/slack-github-action"
args = ["{\"text\":\"The tag [BRANCH_OR_TAG] was just pushed!\"}"]
env = {
SLACK_PATH = "/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
}
}
The Dockerfile and associated scripts and documentation in this project are released under the MIT License.
Content type
Image
Digest
Size
3.4 MB
Last updated
over 7 years ago
docker pull jwinton/slack-github-action