Skip to main content

Send Slack Messages from Workflows

You can send a Slack message at any point in a Workflow using a Slack webhook and a Harness Shell Script step.

This simple integration allows you to notify team members at any point in a deployment.

For more advanced integrations, see Manage User Notifications, Manage Alert Notifications, and Approvals.

note

For steps on sending all User Group notifications to a Slack channel, see Send Notifications Using Slack.

In this topic:

Before You Begin

Step 1: Create a Slack App and Webhook for your Channel

Follow the steps in Slack documentation for creating a Slack app, selecting your channel, and creating a webhook: Sending messages using Incoming Webhooks.

When you are done, you'll have a webhook that looks something like this:

Step 2: Add a Shell Script Step using your Webhook

At any place in your Harness Workflow, add a Shell Script step.

In Script, enter the Slack message using your webhook.

Here is a simple example using the cURL command Slack provides in its Incoming Webhooks page.

curl -X POST -H 'Content-type: application/json' --data '{"text":"simple cURL command example!"}' https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX

When you deploy the Workflow, the message will look something like this:

Here is a more advanced example using bash and Harness built-in variable expressions:

url=https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX  

payload='
{
"text": "Deployed to *${infra.name}*",
"attachments": [
{
"author_name": "${deploymentTriggeredBy}",
"text": "Deployment text",
"color": "#00a3e0"
}
]
}'

curl -s -X POST -H "Content-type: application/json" --data "$payload" $url

When you deploy the Workflow, the message will look something like this:

You can use different variable expressions in your messages. See the following:

Option: Improve Your Message

Slack messages have many formatting and interactive features. You can improve the Slack messages you send from your Workflow using these features.

See the following Slack docs:

Next Steps