1
0
mirror of https://github.com/tektoncd/catalog.git synced 2024-11-21 05:55:35 +00:00
catalog/slackmessage
2020-02-17 15:23:59 -06:00
..
OWNERS Send slack message tasks 2020-02-17 03:47:58 -06:00
README.md Send slack message tasks 2020-02-17 03:47:58 -06:00
send-to-channel-slack.yaml Send slack message tasks 2020-02-17 03:47:58 -06:00
send-to-webhook-slack.yaml fix syntax error in the webhook task 2020-02-17 15:23:59 -06: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 Incomming Webhooks of the 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/master/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

Inputs

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/v1alpha1
kind: TaskRun
metadata:
  name: run-send-to-webhook-slack
spec:
  inputs:
    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/master/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/v1alpha1
kind: TaskRun
metadata:
  name: run-send-to-channel-slack
spec:
  inputs:
    params:
      - name: token-secret
        value: token-secret
      - name: channel
        value: {CHANNEL ID}
      - name: message
        value: "Hello from Tekton!"
  taskRef:
    name: send-to-channel-slack