Transforming Notifications: Transitioning from Office 365 Connectors to Workflows

28 / Jul / 2024 by Karandeep Singh 0 comments

Introduction

As Microsoft Teams evolves, so do its features and functionalities. Recently, Microsoft announced the deprecation of O365 connectors within Teams, encouraging users to migrate to the more flexible and secure Workflows app. If you rely on O365 connectors for notifications and integrations, this blog will help you transition smoothly to using Workflows.

notification

notification

This guide outlines the benefits of switching to Power Automate Workflows and practical steps to implement this change effectively.

power automate

power automate

Understanding the Deprecation

The deprecation of O365 connectors within Teams means that these connectors will no longer function. This change aims to enhance security and provide more robust integration capabilities through the Workflows app. Here’s what you need to know:

  1. Timing: Starting August 15th, 2024, all new Connector creation will be blocked. By October 1st, 2024, all existing connectors will stop working. Official announcement here.
  2. Impact: Notifications and integrations currently managed by O365 connectors will stop working. You need to migrate to Workflows to maintain these functionalities.

Why Transition?

  1. Upcoming Retirement: O365 connectors will be fully deprecated by October 1, 2024, making it imperative to migrate to a supported solution.
  2.  Enhanced Features: Power Automate workflows provide more robust capabilities for automating processes, customizing notifications, and integrating with a broader range of services.
  3. Security and Compliance: Power Automate workflows are built on a secure architecture, aligning with Microsoft’s initiatives to safeguard user data.

Benefits of Power Automate Workflows

  1. Greater Flexibility: You can create adaptive cards that allow for rich interactions, such as buttons and links, enhancing user engagement.
  2. Dynamic Content: Workflows can pull in job parameters, making messages more informative and tailored to your team’s needs.
  3. Wide Integration Options: Power Automate supports a wide array of services, enabling seamless notifications across different platforms.

Step-by-Step Migration Guide

Step 1: Set Up Workflows in MS Teams.

  • Sign in to your Microsoft Teams account. Find workflows on the left panel.
  •  Click on create a new flow.
create workflow

create workflow

  • Select the template “Post to a channel when a webhook request is received
Setup Workflow

Setup Workflow

  • Next, Provide the flow name.
create workflow

create workflow

  • Next, we need to set up the flow by providing the Microsoft team and Microsoft team channel in which we want to send alerts.
Set up flow

Set up flow

  • Finally, click on Create Flow and copy the secret string that will be used by Jenkins for HTTP POST requests for sending notifications.
create flow

create flow

Step 2: Set up Jenkins for Sending Alerts

  • Login into Jenkins. Click on Manage Jenkins and then credentials.
Jenkins

Jenkins

Jenkins Credentials

Jenkins Credentials

  • Create credentials. In kind select secret text and enter the copied webhook into the secret. Provide the ID that will be used in Jenkinsfile for sending alerts. Click on Create.
Jenkins credentials

Jenkins credentials

Step 3: Set up Jenkins Shared Library.

  • Here we are using Jenkins Shared Library for centralizing notification logic to promote reuse across multiple projects.
  • It will help us update notification formats and logic in one place, easing the burden on development teams.

    Jenkins Shared Library

    Jenkins Shared Library

  • Set up an HTTP POST action for Jenkins notifications to send data to your Teams channel.Use the adaptive card format to create your message.
  • Contents of jenkinsNotifications.groovy:
def notify(String status, String message, String credentialsId) {
  def colors = [
      'Success': 'Good', // green
      'Failure': 'Attention' // red
  ]

  if (!colors.containsKey(status)) {
      error "Invalid status: $status"
  }

  def color = colors[status]

  def title = "Jenkins Build Notification"

  withCredentials([string(credentialsId: "${credentialsId}", variable: 'webhookUrl')]) {
      def payload = [
        "type": "message",
        "attachments": [
            [
              "contentType": "application/vnd.microsoft.card.adaptive",
              "content": [
                  "\$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
                  "type": "AdaptiveCard",
                  "version": "1.3",
                  "body": [
                    [
                        "type": "TextBlock",
                        "size": "Medium",
                        "weight": "Bolder",
                        "text": "${title}"
                    ],
                    [
                        "type": "ColumnSet",
                        "columns": [
                          [
                              "type": "Column",
                              "items": [
                                [
                                    "type": "Image",
                                    "style": "Person",
                                    "url": "https://ftp-chi.osuosl.org/pub/jenkins/art/jenkins-logo/1024x1024/logo.png",
                                    "altText": "Jenkins",
                                    "size": "Medium"
                                ]
                              ],
                              "width": "auto"
                          ],
                          [
                              "type": "Column",
                              "items": [
                                [
                                    "type": "TextBlock",
                                    "weight": "Bolder",
                                    "text": "Jenkins Notification",
                                    "wrap": true
                                ]
                              ],
                              "width": "auto"
                          ]
                        ]
                    ],
                    [
                        "type": "TextBlock",
                        "weight": "Bolder",
                        "color": "${color}",
                        "text": "${status}",
                        "wrap": true
                    ],
                    [
                        "type": "TextBlock",
                        "text": "${message}",
                        "wrap": true
                    ]
                  ]
              ]
            ]
        ]
      ]

      def response = httpRequest(
        httpMode: 'POST',
        contentType: 'APPLICATION_JSON',
        requestBody: groovy.json.JsonOutput.toJson(payload),
        url: webhookUrl
      )

      echo "Response: ${response}"
  }
}

Step 4: Update Jenkins Job Configuration to call Shared Library.

@Library('your-shared-library') _
pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                // Your build steps here
            }
        }
    }
    post {
        success {
            script {
                def successMessage = """\
              ${appName} application Jenkins Job SUCCESS in ${envName} environment.\n
            Jenkins Build URL: ${BUILD_URL}\n
              Jenkins Build Number: ${BUILD_NUMBER}\n
            """.stripIndent()
                // Call the shared library method
                jenkinsNotifications.notify("Success", successMessage, "jenkins-test-success")
            }
        }
    }
}

Step 5: Test and Validate

  • Run a test job to ensure notifications are sent correctly.
  • Check the Teams channel to verify that the messages appear as intended.
Microsoft Teams Alert

Microsoft Teams Alert

Step 6: Iterate Based on Feedback

Gather input from your team on the new notification format and make adjustments as necessary to enhance clarity and engagement.

Conclusion

Migrating from O365Connector to Power Automate Workflows is a strategic move that will keep your Jenkins notifications functional and enhance their effectiveness. By following the outlined steps, teams can ensure a smooth transition, maintaining communication and collaboration in the age of modern DevOps.

At TO THE NEW, we are dedicated to helping you navigate this migration and other Jenkins & Microsoft-related work. Our expertise ensures a seamless transition and optimization of your workflows, enhancing your overall DevOps processes—partner with us for a streamlined and efficient journey in adopting the latest tools and technologies.

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *