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.
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
Server URL: https://hooks.slack.com/services/
Service Connection Name: Slack
Description: A Generic Slack Service connection.
$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.
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.