1
0
mirror of https://github.com/tektoncd/catalog.git synced 2024-12-02 06:52:15 +00:00
catalog/slackmessage
ishani2412 c89d3965b7 Improve Readme.md
PR to improve the Readme.md migrating the install task URL from
master to v1beta1

Signed-off-by: ishani2412 <ishani.1613039@kiet.edu>
2020-06-02 09:03:51 +01:00
..
OWNERS Send slack message tasks 2020-02-17 03:47:58 -06:00
README.md Improve Readme.md 2020-06-02 09:03:51 +01:00
send-to-channel-slack.yaml Fix some typos in slack message 2020-04-20 11:50:06 +01:00
send-to-webhook-slack.yaml Fix some typos in slack message 2020-04-20 11:50:06 +01:00

Post a message to slack

These tasks post a simple message to a slack channel. There are multiple ways to send a message to slack. Each task here uses different method.

send-to-webhook-slack

This task uses Incoming Webhooks of slack to send the message. Follow instructions here to generate a webhook URL.

Install the Task and create a secret

kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/v1beta1/slackmessage/send-to-webhook-slack.yaml

Create a secret that has the generated webhook URL

Example webhook-secret.yaml

kind: Secret
apiVersion: v1
metadata:
  name: webhook-secret
stringData:
  url: {generated webhook URL}

Example kubectl command

kubectl apply -f webhook-secret.yaml

Parameters

  • webhook-secret: The name of the secret that has the webhook URL. The key for the URL is url

  • message: Plain text message to be posted in the slack channel

Usage

This TaskRun runs the Task to post a message to the channel that the webhook URL is associated with.

apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
  name: run-send-to-webhook-slack
spec:
  params:
  - name: webhook-secret
    value: webhook-secret
  - name: message
    value: "Hello from Tekton!"
  taskRef:
    name: send-to-webhook-slack

send-to-channel-slack

This task uses chat.postMessage slack REST api to send the message. Follow instructions here to obtain the OAuth access token for the bot app with chat:write scope. The app must join the channel before the message posted by this task run. (invite the app in the channel)

Install the Task and create a secret

kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/v1beta1/slackmessage/send-to-channel-slack.yaml

Create a secret that has the OAuth token of the bot app.

Example token-secret.yaml

kind: Secret
apiVersion: v1
metadata:
  name: token-secret
stringData:
  token: {OAuth token for the bot app}

Example kubectl command

kubectl apply -f token-secret.yaml

Inputs

Parameters

  • token-secret: The name of the secret that has the OAuth token. The key for the OAuth-token is token

  • channel: channel id or channel name where the message is posted

  • message: Plain text message to be posted in the slack channel

Usage

This TaskRun runs the Task to post a message to the channel.

apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
  name: run-send-to-channel-slack
spec:
  params:
  - name: token-secret
    value: token-secret
  - name: channel
    value: {CHANNEL ID}
  - name: message
    value: "Hello from Tekton!"
  taskRef:
    name: send-to-channel-slack