> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/utilities/slack-notify-step.md).

# Slack Notify step

Send a notification from a pipeline to a Slack channel.

This topic describes the settings for the Slack Notify step available in Continuous Delivery (CD) and custom stages.

The Slack Notify step lets you send notifications to a Slack channel or Slack thread during a pipeline execution.

## What you will learn from this topic

* How to add the Slack Notify step inside a container-based step group in a CD or custom stage
* How to configure the step to send messages to a Slack channel or thread using a Slack secret key
* How to send custom text messages or Slack Block Kit payloads from a pipeline execution

## Before you begin

Before you begin, make sure you have the following:

* A Kubernetes cluster for the container-based step group that contains the Slack Notify step.
* A Slack secret key that you can create or select in the step.

## Step-by-step guide <a href="#step-by-step-guide" id="step-by-step-guide"></a>

The step-by-step guide is available in the following tabs:

{% tabs %}
{% tab title="Interactive guide" %}
{% embed url="<https://app.tango.us/app/embed/230e7552-81fa-4a42-9baa-3a11100ef8ad>" %}
{% endtab %}

{% tab title="Step-by-step guide" %}
**Setting up a Slack Notify step**

Follow these steps to set up a Slack Notify step:

1. **Create Pipeline**
   * Select **Create Pipeline** and enter your pipeline name.
2. **Add Stage**
   * Select **Add Stage**. You can select any stage as this step is available across stages.
3. **Navigate to Execution Tab**
   * Within the stage, go to the **Execution** tab.
4. **Add a Step Group**
   * Add a step group.
   * Enable **Container Based Execution** by setting it to `true`.
   * Select a **Kubernetes Cluster**.
   * Save the step group.
5. **Add Slack Notify Step**
   * Within the step group, add a step.
   * Select **Slack Notify** under **Miscellaneous**.
6. **Configure Slack Notify Step**
   * Select the **Channel** checkbox or the **Email** checkbox.
   * For sending notifications to a channel, provide the channel details where you want your message to be published.
   * For sending notifications to an email address, provide the email details where you want your message to be published.
   * Optionally, send a custom text message or a Slack block.
   * Under **Slack Secret Key**, create or select your Slack secret key.
   * Optionally, specify the thread in which you want the notification to be received.
7. **Save and Run**
   * Save your pipeline configuration and run the pipeline.
     {% endtab %}
     {% endtabs %}

{% hint style="info" %}
The Slack Notify step **can be added in any stage**, but it is **only available within a step group**.
{% endhint %}

## Supported recipients and messages <a href="#supported-recipients-and-messages" id="supported-recipients-and-messages"></a>

The Slack Notify step supports the following recipient and message types.

### Types of recipients supported <a href="#types-of-recipients-supported" id="types-of-recipients-supported"></a>

The following types of recipients are supported:

* **Email**: The email address associated with the Slack account. This can be used to send notifications to a specific recipient.
* **Channel**: The channel where the notification is to be sent. Provide the **channel-id** of the channel.

### Types of messages supported <a href="#types-of-messages-supported" id="types-of-messages-supported"></a>

The following types of messages are supported:

* **Message**: A plain text format. This can be a fixed value, runtime input, or an expression.
* **Block**: You can send Slack Block notifications. Ensure that the block is enclosed in an array. For more information on Slack Blocks, go to the [Slack documentation](https://api.slack.com/reference/block-kit/blocks#header).

<details>

<summary>Sample block message</summary>

```json
[{
    "type": "header",
    "text": {
        "type": "plain_text",
        "text": "This is a Header block"
        }
}]
```

This block sends the notification "This is a Header block" in heading 1 format to the recipient.

</details>

## Send notifications to a specific thread in a channel <a href="#sending-notifications-to-a-specific-thread-in-a-channel" id="sending-notifications-to-a-specific-thread-in-a-channel"></a>

To send notifications to a specific **thread**, provide the `thread_ts` details under Thread. For more information on how to get `thread_ts` details, see the [Slack documentation](https://api.slack.com/methods/conversations.replies).

**YAML example**

The following example shows the Slack Notify step in a stage.

<details>

<summary>Sample YAML describing the Slack Notify step</summary>

```yaml
stages:
    - stage:
        name: slack-step
        identifier: slack-step
        description: ""
        type: Custom
        spec:
          execution:
            steps:
              - stepGroup:
                  name: container
                  identifier: container
                  steps:
                    - step:
                        type: SlackNotify
                        name: SlackNotify_1
                        identifier: SlackNotify_1
                        spec:
                          channel: CHANNEL_ID
                          messageContent: <+input>
                          token: SLACK_TOKEN
                          threadTs: THREAD_ID
                  stepGroupInfra:
                    type: KubernetesDirect
                    spec:
                      connectorRef: KUBERNETES_DELEGATE
                      namespace: NAMESPACE
            rollbackSteps: []
          serviceDependencies: []
        tags: {}
```

</details>

Upon a successful pipeline run, the message configured in the Slack Notify step is sent to the designated Slack channel or recipient.

![Execution](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-2e7447c2babca8e399409e47fc0948318bcd826f%2Fslack-notify.png?alt=media)

## Slack Notify step sample <a href="#slack-notify-step-sample" id="slack-notify-step-sample"></a>

Go to the [Harness Community Repository](https://github.com/harness-community/harnesscd-example-apps/tree/master/cd-features/slack-notify-step) for an example of how to use the Slack Notify step in Harness.

This repository provides a ready-to-use sample application and the necessary configuration files to help you get started quickly.

## Next steps

* [Notify users of pipeline events](/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/notify-users-of-pipeline-events.md)
* [CD best practices](/continuous-delivery/troubleshooting-and-resources/cd-best-practices.md)

{% @harness-feedback/feedback %}
