In this tutorial you will learn how to enable Slack notifications for certain events in Humanitec. In this example, we will post to Slack once a Deployment finished. To enable this, we will show you how to create webhooks in Humanitec and set up a workflow in Slack to post the message.
In this tutorial we will show you how to
- Create a Slack Workflow
- Create a webhook in Humanitec
- Test your webhook
Before starting this tutorial, you’ll need:
- A Humanitec account
- An App set up in Humanitec
- A Slack organization using a paid plan
Step 1: Create a Slack Workflow
The fastest way of getting a message into a channel in Slack is with Slack Workflows. We will build a workflow that is triggered by a webhook and then posts a message to a channel.
Open the Workflow Builder
You can access the workflow builder in Slack by clicking your Slack organization's name in the top left of the desktop version of Slack. Select Tools → Workflow Builder.
Create a new workflow
In the Workflow Builder, click the Create button in the top right. When prompted, choose a name for your workflow.
Choose a "Webhook" trigger
Click the Select button next to "Webhook (advanced)" from the options to start the workflow.
Configure the webhook
The webhook request generated by Humanitec will contain a number of variables that we need to configure in Slack.
You should add the following variables:
You can add these variables by clicking the Add Variable button.
Once the variables are added, your dialog should look like this:
Click Save to move to the next step.
Add a step to your workflow
Next, you will be prompted to add a step to the workflow. Click Add Step.
Then choose Send a message step by clicking the Add button next to "Send a message".
Choose the channel you want to send to and craft your message. You can insert the variables you added earlier into the message by clicking the Insert a variable button. You can also add formatting as you would in Slack. A preview of how your message will look is shown at the bottom of the window.
Once you are happy with your message, click Save.
Publish your Workflow
Click the Publish button in the top right of the Workflow Builder to publish your workflow.
Next you will be prompted with the URL to use for the webhook. Make sure you copy this somewhere safe. You will need to paste it into Humanitec later.
Step 2: Create a Webhook in Humanitec
- Enter an ID you will use to identify this webhook in future. It must be a valid Humanitec ID.
- Paste in the URL you copied in the last step of creating your Slack workflow.
- Select the Deployment → Finished trigger to make the webhook be fired once every deployment has completed.
- Click the Create button and finish setting up the webhook.
Step 3: Test your webhook
When you next deploy to an Environment in the App, you should get a Slack message in the channel you defined in your workflow!
In this tutorial, you learned how to enable Slack notifications depending on deployments in Humanitec. We tackled how to create a workflow in Slack, how to create a webhook in Humanitec and how to test your webhook.