This Task posts a message to the Slack channel(s) integrated with your Continuous Delivery toolchain.
The task retrieves a Slack integration(s) from the Toolchain, filtered on the Slack domain (if passed as a parameter) and posts the message to the corresponding channel(s).
The message can be:
-
passed as a parameter
- a static Slack formatted JSON payload
- a static text message (that will be converted to Slack JSON payload)
-
dynamically injected
- by a bash script
- based on the output of previous task(s) stored in the PVC
-
default message if not set
Create a Slack Webhook.
Add a Slack integration to your Continuous Delivery toolchain
- Add a github integration in your Toolchain to the repository containing the task (https://github.com/open-toolchain/tekton-catalog)
- Add that github integration to the Definitions tab of your Continuous Delivery Tekton pipeline, with the Path set to
slack
.
- domain: (optional) the Slack domain to send the message to. If not set, the message will be posted to the Slack integration(s) as defined in the Toolchain.
- channel: (optional) the Slack channel to send the message to. When set, overrides the default channel as set in the Slack Webhook URL. Only non-private channel can override the default channel. If the target channel is a private channel, the Slack Webhook URL in the Slack toolchain integration card needs to be updated.
- message-format: (optional) the format of the message. Value: text(default) or JSON.
- message-script: (optional) Shell script that provides messsage content.
- message: (optional) the message to send to Slack.
- exit-on-error: flag (
true
|false
) to indicate if the task should fail or continue if unable to process the message or post to Slack (defaultfalse
).
- workspace: A workspace that contain data useful for the script/slack message resolution. Should be marked as optional when Tekton will permit it.
None.
The sample
sub-directory contains an EventListener and Pipeline definition that you can include in your Tekton pipeline configuration to run an example of the slack-post-message
task.
-
Create or update a Toolchain so it includes:
- a Slack integration
- the repository containing this tekton task
- a Tekton pipeline definition
-
Add the definitions of this task and the sample (
slack
andslack/sample
paths) -
Add the environment properties as needed:
domain
(optional) the Slack domain to send the message to.channel
(optional) the channel to post to (overrides the dafault channel as set in the Slack webhook).message-format
(optional) the format of the message (text or JSON).message-script
(optional) Shell script that provides messsage content.message
(optional) the message to post to Slack.
Note: when using JSON format, the message is posted as-is to Slack.
-
Create a manual trigger to start the sample listener
-
Run the pipeline
-
The message is posted to Slack
-
Optional: check the execution log
-
Optionnal: Create a message using snippet
a) Define the snippet in the
message-script
environment property of the pipelinemessage-script: `echo 'Message sent from PipelineRun' ${PIPELINE_RUN_NAME}; echo 'uid:' ${PIPELINE_RUN_ID}; echo 'buildNumber:' ${BUILD_NUMBER};`
Note: this could also be done in the trigger-template or pipeline definition
b) After running the pipeline, a new message like the following should have been posted to the Slack channel
c) Check the execution log