Simple Slack Send is designed to push templated slack notifications from you CI pipelines using Slack's incoming webhooks.
Simple Slack Send uses Jinja2 under the hood to produce Slack messages in JSON format. You can use any expression (values, includes, conditions, loops etc.) that is allowed by Jinja. If the rendering engine's output is empty, no message is sent.
Jinja templates are fed with values from multiple sources given as command arguments:
- env files with key-value pairs ie.
-e production.env
or--env-file=staging.env
- json files ie.
-j terraform-output.json
or--env-file=infrastructure.json
- key-value pairs provided as command arguments ie.
-v env_name=jupiter
or--var instance_type=small
- system environment - turned on/off with
--sys-env
/--no-sys-env
option; on by default
You can pass Slack's webhook url by settings SLACK_WEBHOOK_URL
env variable or using --webhook-url
argument.
message.json.tpl:
{% if BITBUCKET_EXIT_CODE == "0" %}
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":large_green_circle: Commit {{ BITBUCKET_COMMIT }} built successfully."
}
}
]
}
{% else %}
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":red_circle: Commit {{ BITBUCKET_COMMIT }} failed to build. Visit <https://bitbucket.org/{{ BITBUCKET_REPO_FULL_NAME }}/pipelines/results/{{ BITBUCKET_BUILD_NUMBER }}|pipeline> for details."
}
}
]
}
{% endif %}
simple-slack-send message.json.tpl