How to send notifications to Microsoft Teams through FlexDeploy

Objective

You have a working FlexDeploy Release/Pipeline. The goal of the tutorial is to send notifications to Microsoft Teams based on certain Release/Pipeline milestones being achieved.  The tutorial will include:

  • Configure FlexDeploy Webhooks to send messages to Teams

Configure a FlexDeploy Webhook to send Teams notifications

  • It may sound a bit complex with the terminology but once we understand how to configure it, you will find it pretty straightforward.

  • First review the below URL to understand the steps to configure an Outbound Webhook.

  • Basically, there are two parts to a Webhook,

    • Filter – This is the criteria that determines when the Webhook will be triggered.

    • Script – This script is responsible for sending the Teams Notification.

  • Let's understand in a bit more detail. Below are some of the FlexDeploy events that can trigger a Webhook. The complete list of available events can be found in the link below
    Events

Filter

  • One event can be picked up by one Listener/Webhook only. So in case you have multiple Listeners configured with the same criteria (Filter), the Listener from the top of the list that satisfies the criteria (Filter) first will process the event message.

  • So it's absolutely essential to have a proper Event Message Filter. We have added the below filter.

if(EVENT.payload.environment.environmentCode.equals("DEV") && EVENT.payload.pipeline.pipelineName.equals("Teams_Dummy_Pipeline")) { return true; } else { return false; }
  • It’s evident from the logic that we want the Webhook to be triggered only when the Pipeline being executed is - Teams_Dummy_Pipeline and the Stage executed/Environment code is DEV

  • Now the obvious question that will arise is, where exactly are we getting the EVENT.payload object.

  • As mentioned in the earlier step, events get generated under certain conditions only. They do get generated as a JSON payload with relevant details, it’s processed by Webhook Listener.

Event Payload

  • You can get a detailed structure of the payload for each event from the below link.
    Events

  • Navigate to the Messages section on the Outgoing Webhooks page to view a summary of all the previously processed events.

  • You can find the actual event message payload details and any available logs from the processing of the event here.

If this is your first time and you are still confused with the idea of the payload, you can start by creating Webhook without a filter. You will still be able to view the Event payloads. However, it is strongly recommended to always use some filtering in real-life scenarios.

Script - Send notification to Teams Channel

  • Using the same approach, evaluating the payload we can easily write our groovy script.

def listenerName = "Send Teams Notification on Stage Completion"; LOG.info("Running listener: ${listenerName}"); // Sending the message to Teams Channel MICROSOFTTEAMS.sendTeamsWebhookMessage("https://<webhook url goes here>","Title",""Message"); // or MICROSOFTTEAMS.sendTeamsWebhookMessage("https://<webhook url goes here>",jsonVariableOfMessageCard);

Debugging execution

  • It can happen, that there could be an issue with the script. In such a scenario, navigate to the Messages page and use the actions menu to view the logs.

 

Congratulations! You have successfully completed the Teams Notification Integration with FlexDeploy.

Now that you have completed Teams setup successfully in FlexDeploy, the same can be reused for all other Teams notifications as well. Simply configure your Teams message filter and content as mentioned above and FlexDeploy will take care of the rest.

The following macros are not currently supported in the footer:
  • style