Skip to main content

Slack

Description

This plugin enables you to send data to a Slack channel.

Source Code: https://github.com/go-vela/vela-slack

Registry: https://hub.docker.com/r/target/vela-slack

Usage

NOTE:

Users should refrain from using latest as the tag for the Docker image.

It is recommended to use a semantically versioned tag instead.

Sample of sending a message:

steps:
- name: message
image: target/vela-slack:latest
pull: always
parameters:
text: "Hello World!"

Sample of sending a message with formatting:

steps:
- name: message-with-formatting
image: target/vela-slack:latest
pull: not_present
parameters:
- text: "Hello World!"
+ text: "Hello Repo {{ .RepositoryName }}!"

Sample of sending a message with local attachment file:

steps:
- name: message-with-attachment
image: target/vela-slack:latest
secrets: [ slack_webhook ]
parameters:
- text: "Hello World!"
filepath: slack_attachment.json
remote: false

Sample of sending a message with remote attachment file:

steps:
- name: message-with-remote-attachment
image: target/vela-slack:latest
secrets: [ slack_webhook ]
parameters:
- text: "Hello World!"
filepath: slack_attachment.json
remote: true
registry: https://github.com

content of slack_attachment.json:

{
"attachments": [
{
"fallback": "Required plain-text summary of the attachment.",
"color": "#36a64f",
"pretext": "Optional text that appears above the attachment block",
"author_name": "Bobby Tables",
"author_link": "http://flickr.com/bobby/",
"author_icon": "http://flickr.com/icons/bobby.jpg",
"title": "Slack API Documentation",
"title_link": "https://api.slack.com/",
"text": "Build: {{ .BuildNumber }}",
"fields": [
{
"title": "Priority",
"value": "High",
"short": false
}
],
"image_url": "http://my-website.com/path/to/image.jpg",
"thumb_url": "http://example.com/path/to/thumb.png",
"footer": "Slack API",
"footer_icon": "https://platform.slack-edge.com/img/default_application_icon.png",
"ts": 123456789
}
]
}

NOTE:

To use any variables within attachments the file must be saved in the attachment format and be a JSON file.

The configuration below is pulled almost directly from the Slack Message Builder attachments example.

Secrets

NOTE: Users should refrain from configuring sensitive information in your pipeline in plain text.

Internal

The plugin accepts the following parameters for authentication:

ParameterEnvironment Variable Configuration
webhookPARAMETER_WEBHOOK, SLACK_WEBHOOK

Users can use Vela internal secrets to substitute these sensitive values at runtime:

steps:
- name: message
image: target/vela-slack:latest
pull: always
+ secrets: [ slack_webhook ]
parameters:
text: "Hello World!"
- webhook: http://slack.example.com

This example will add the secret to the message step as environment variables:

  • SLACK_WEBHOOK=<value>

External

The plugin accepts the following files for authentication:

ParameterVolume Configuration
webhook/vela/parameters/slack/webhook, /vela/secrets/slack/webhook

Users can use Vela external secrets to substitute these sensitive values at runtime:

steps:
- name: message
image: target/vela-slack:latest
pull: always
parameters:
text: "Hello World!"
- webhook: http://slack.example.com

This example will read the secret value in the volume stored at /vela/secrets/

Parameters

NOTE:

The plugin supports reading all parameters via environment variables or files.

Any values set from a file take precedence over values set from the environment.

The following parameters are used to configure the image:

NameDescriptionRequiredDefaultEnvironment Variables
channelSlack channel to send data tofalseN/APARAMETER_CHANNEL
SLACK_CHANNEL
filepathfile path to attachment JSON filefalseN/APARAMETER_FILEPATH
SLACK_FILEPATH
icon_emojiSlack emoji to use for the iconfalseN/APARAMETER_ICON_EMOJI
SLACK_ICON_EMOJI
icon_urlSlack emoji URL to use for the iconfalseN/APARAMETER_ICON_URL
SLACK_ICON_URL
log_levelset the log level for the plugintrueinfoPARAMETER_LOG_LEVEL
SLACK_LOG_LEVEL
texttop level text to display in messagefalseN/APARAMETER_TEXT
SLACK_TEXT
thread_tstimestamp of the thread postfalseN/APARAMETER_THREAD_TS
SLACK_THREAD_TS
webhookSlack webhook url to send data totrueN/APARAMETER_WEBHOOK
SLACK_WEBHOOK

Template

COMING SOON!

Troubleshooting

You can start troubleshooting this plugin by tuning the level of logs being displayed:

steps:
- name: message
image: target/vela-slack:latest
pull: always
parameters:
+ log_level: trace
text: "Hello World!"

Below are a list of common problems and how to solve them: