Microsoft Teams Integration

Hey All!

I’ve had a few conversations around integrations with Harness and other tools, what is and is not supported, and even when certain integrations would be coming. One of the great things about a Software-as-a-Service like Harness is that you get rapid integration support with use-case-directed development.

Obviously, we will need to supplement a stop-gap for some of these integrations in the meantime. The technology integration that this post covers will be Microsoft Teams Notifications

Microsoft Teams Incoming Webhook

The first step is to either select or create a channel in Microsoft Teams

The next step is to click the three dots to the right of the channel name and then select Connectors

In the Connectors page, search for Incoming Webhook, give it a name (like Harness), and upload the desired image

Once that is done, it is time to build out the desired cURL payload that you want to use for the notification

Notification Command

First, we will build out the command to be the notification. This is the command I’m using:

WEBHOOK_URL='<Microsoft Teams Webhook>'

curl -H "Content-Type: application/json" 
-d "{\"title\":\"Harness: ${workflow.name}-${msg}\",
\"themeColor\":\"25ADE4\",\"summary\":\"Harness Deployment\",
\"sections\":[{\"facts\":[
{\"name\":\"Deployment URL\",\"value\":\"${deploymentUrl}\"},
{\"name\":\"Service Name\",\"value\":\"${service.name}\"},
{\"name\":\"Artifact\",\"value\":\"${artifact.metadata.image}:${artifact.metadata.tag}\"},
{\"name\":\"Environment\",\"value\":\"${env.name}\"},
{\"name\":\"Workflow\",\"value\":\"${workflow.name}\"},
{\"name\":\"Triggered By\",\"value\":\"${deploymentTriggeredBy}\"}]}]}" 
"${WEBHOOK_URL}"

NOTE: The entire curl command must be a single line

Let’s break down this command:

  • WEBHOOK_URL - The Webhook URL from that you set up in the Microsoft Teams channel
  • ${workflow.name} - Has Harness plug in the name of the Workflow into the channel title and the Workflow Name Key:value pair
  • ${msg} - Takes a user-specified messaged (i.e. Started, Finished, Rolling Back, etc.) and add it to the end of the Title
  • ${deploymentUrl} - Passes the URL of the deployment to the channel
  • ${service.name} - Passes the name of the Harness Service to the channel
  • ${artifact.metadata.image}:${artifact.metadata.tag} - Passes the Artifact Name and Tag to the channel
  • ${env.name} - Passes the Environment Name to the channel
  • ${deploymentTriggeredBy} - Either the person or trigger that was used to do the deployment

The command itself is broken down as follows:

  • Title is the message header in Microsoft Teams
  • Theme Color is the colored line above the message header (25ADE4 is the Harness Blue from our website)
  • Summary doesn’t actually show in Microsoft Teams, but it is required for the webhook to work
  • Sections and Facts are tied together for the key:value pair list to be put in the channel

Harness Setup

Start by going to the Template Library in Harness (Setup > Template Library) and create a new SSH Command

Add the command in the script window and add a msg variable to the bottom of the form

Once that is done, we can link that script in the Workflow for proper notifications

Workflow Integration

Go to the desired phase, add a new command, and select Select from Shared Template Library in the top right, and select Link to the right of the desired template

Once that is linked in the desired spot, the only thing required is to put in the appropriate Message info.

If you want to use this in a more advanced way as well, you could put this in the rollback steps!

You’re all set to receive Microsoft Teams notifications!

Will update this post as some functionality is improved or if new issues arise.

Don’t forget to Comment/Like/Share!

3 Likes

Awesome contribution!

1 Like

Awesome post Bryan! We have many customers who have been asking for an integration around MS Teams.

2 Likes