iainrough
Posted on May 16, 2021
Need to send a slack notification from an Azure DevOps pipeline? The InvokeRESTAPI@1 task is one of the most versatile and useful in Azure DevOps. It handles sending messages to Slack in a couple of lines of YAML.
The Service Connection
Project Settings > Pipelines > Service connections
The service connection is where we define the URL we are going to post to. For this we will use the Generic Service Connection. You navigate to Project Settings > Pipelines > Service connections or append this string after your project name in the URL _settings/adminservices
The fields we need to fill:
Server URL: https://hooks.slack.com/services/
Service Connection Name: Slack
Description: A Generic Slack Service connection.
The other Variables in the task
$body: You can either generate this variable or Input the body inline. Here is an example body:
So here you can see we are passing variables like the PullId and using them in the Slack Message. The ability to use any of the variables in the pipeline allows for detailed Slack Messages.
$urlSuffix: T778W530Z/B021W918BNH/HQIPtyCfACfs5WVXg1w7b4Xk
This is the magic bit for Slack, I would recommend storing this value as secret or getting it from your Azure Key Vault.
Simple Quick and Easy.
Posted on May 16, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.