# Sending pipeline status to Slack Here's the recipe I followed to make a simple POC of how to send notifications from the Tekton pipeline (on kind in my case) to Slack (my own slack workspace here) ## Creating a Slack App I simply followed [Slack docs](https://api.slack.com/tutorials/tracks/getting-a-token) on getting a new token. It turns out that right now, you need a slack App to obtain a token. You can no longer create user tokens, now called `legacy test tokens`. But things turned out rather easy: On the page mentioned above, I followed **Create a pre-configured app** link ![](https://i.imgur.com/AjqXOZq.png) Next, I followed the instructions * selecting my test workspace * then, editing the app conf to limit its permission to just writing to channels, like so ```yaml= _metadata: major_version: 1 minor_version: 1 display_information: name: tekton-pipeline description: An app with bot tokens that can do quite a lot background_color: "#d982b5" features: bot_user: display_name: TektonBot always_online: true app_home: home_tab_enabled: false messages_tab_enabled: true messages_tab_read_only_enabled: true oauth_config: scopes: bot: - chat:write.customize - chat:write.public - chat:write settings: interactivity: is_enabled: true org_deploy_enabled: false socket_mode_enabled: true ``` * Next, installing the App to my workspace and clicking `Allow` to agree with the permissions set above ![](https://i.imgur.com/Haepa45.png =400x300) * You could then customize the App by selecting its icon and background color * You can ignore the `App-Level Tokens` in this page, and instead navigate to `OAuth & Permissions` submenu (available on the Settings menu on the left), and you'll find the token for your App under `OAuth Tokens for Your Workspace` section.** It starts with `xoxb-` ** ## Preparing your Kubernetes namespace ### Token secret I more or less followed the instructions for [send-to-channel-slack](https://hub.tekton.dev/tekton/task/send-to-channel-slack) tekton task from the Tekton Hub. I created a secret, with name `token-secret` in the namespace hosting my pipeline, of type generic with a single key, `token`, containing the App token I just created above. Example ```yaml= kind: Secret apiVersion: v1 metadata: name: token-secret stringData: token: {OAuth token for the bot app} ``` ### send-to-channel-slack Task I started from the https://github.com/okd-project/okd-operator-pipeline/ repository. I updated [manifests/tekton/tasks/base/kustomization.yaml](https://github.com/okd-project/okd-operator-pipeline/blob/main/manifests/tekton/tasks/base/kustomization.yaml) to add the task directly from Tekton Hub, like this: ```yaml= namePrefix: bases: - git-clone.yaml - container-all.yaml - bundle-all.yaml - https://raw.githubusercontent.com/tektoncd/catalog/main/task/send-to-channel-slack/0.1/send-to-channel-slack.yaml ``` Then simply applied: `kubectl apply -k environments/overlays/kind -n okd-team` ## Add a task to your pipeline In order not to do any damage to the existing pipeline in the repo, I created a new dummy pipeline, which I added to the list of bases in [manifests/tekton/pipelines/base/kustomize.yaml](https://github.com/okd-project/okd-operator-pipeline/blob/main/manifests/tekton/pipelines/base/kustomization.yaml): ```yaml= apiVersion: tekton.dev/v1beta1 kind: Pipeline metadata: name: pipeline-slack-hello namespace: okd-team spec: params: - name: channel description: The ID of the slack channel type: string - name: repo-name description: The repo name type: string - name: bundle-version description: The bundle version type: string tasks: - name: talk-to-slack params: - name: token-secret value: token-secret - name: channel value: $(params.channel) - name: message value: Going to run operator pipeline on repo $(params.repo-name) to build $(params.bundle-version) taskRef: kind: Task name: send-to-channel-slack ``` Finally, I ran this pipeline using a PipelineRun manifest like this one: ```yaml= apiVersion: tekton.dev/v1beta1 kind: PipelineRun metadata: namespace: okd-team name: first-report-to-slack spec: podTemplate: nodeSelector: kubernetes.io/hostname: kind-control-plane params: - name: channel value: C5QFT7ZAN - name: bundle-version value: v0.0.1 - name: repo-name value: node-observability-operator pipelineRef: name: pipeline-slack-hello ``` Apply both, and use: ```bash kubectl apply -k environments/overlays/kind kubectl apply -f first-report-to-slack.yaml ``` Pipeline logs ```bash= $ tkn pr logs first-report-to-slack [talk-to-slack : post] % Total % Received % Xferd Average Speed Time Time Time Current [talk-to-slack : post] Dload Upload Total Spent Left Speed 100 1084 0 968 100 116 3237 387 --:--:-- --:--:-- --:--:-- 3625 [talk-to-slack : post] {"ok":true,"channel":"C5QFT7ZAN","ts":"1668688017.496119","message":{"bot_id":"B04BCSANNPL","type":"message","text":"Going to run operator pipeline on repo node-observability-operator to build v0.0.1","user":"U04BCP8RTS7","ts":"1668688017.496119","app_id":"A04BCS8BK6E","blocks":[{"type":"rich_text","block_id":"D5tm","elements":[{"type":"rich_text_section","elements":[{"type":"text","text":"Going to run operator pipeline on repo node-observability-operator to build v0.0.1"}]}]}],"team":"T5QFT7WLA","bot_profile":{"id":"B04BCSANNPL","app_id":"A04BCS8BK6E","name":"TektonBot","icons":{"image_36":"https:\/\/a.slack-edge.com\/80588\/img\/plugins\/app\/bot_36.png","image_48":"https:\/\/a.slack-edge.com\/80588\/img\/plugins\/app\/bot_48.png","image_72":"https:\/\/a.slack-edge.com\/80588\/img\/plugins\/app\/service_72.png"},"deleted":false,"updated":1668684859,"team_id":"T5QFT7WLA"}},"warning":"missing_charset","response_metadata":{"warnings":["missing_charset"]}} ```