Setting up Azure DevOps Pipeline connection with MSTeams master/main branch builds
In today's fast-paced software development world, it is essential to have a robust and efficient build and release pipeline. Azure DevOps provides a powerful set of tools to create and manage such pipelines. In this article, we will learn how to set up a pipeline to build and deploy code from the master or main branch and receive alerts in an MSTeams channel whenever the pipeline completes.
Introduction
Azure DevOps is a cloud-based DevOps service that provides a set of tools to manage the entire software development lifecycle. It offers services like source control, continuous integration/continuous delivery (CI/CD), testing, artifact management, and collaboration tools.
Microsoft Teams (MSTeams) is a unified communication and collaboration platform that combines persistent workplace chat, video meetings, file storage, and application integration.
In this article, we will learn how to integrate Azure DevOps pipelines with MSTeams to receive alerts whenever the pipeline completes.
Prerequisites
To follow this article, you need the following:
- An Azure DevOps account
- A repository with code to build and deploy
- An MSTeams account with a channel to receive alerts
Setting up Azure DevOps Pipeline
To set up an Azure DevOps pipeline, follow these steps:
- Create a new pipeline in Azure DevOps.
- Choose the source control where your code is located.
- Choose the type of pipeline you want to create.
- Configure the pipeline with the necessary steps to build and deploy your code.
- Save and queue the pipeline.
To learn more about setting up an Azure DevOps pipeline, refer to the official documentation.
Setting up MSTeams Channel
To set up an MSTeams channel to receive alerts, follow these steps:
- Open MSTeams and navigate to the team where you want to add the channel.
- Click on the ellipsis (...) next to the team name and select "Add channel."
- Give the channel a name and click "Add."
Setting up Azure DevOps Pipeline with MSTeams Channel
To set up Azure DevOps pipeline with MSTeams channel, follow these steps:
- Navigate to the pipeline you created in Azure DevOps.
- Click on the ellipsis (...) next to the pipeline name and select "Triggers."
- Enable the "Continuous Integration" trigger and select the branch you want to build and deploy.
- Click on the "Add" button next to "Post-build script path" and enter the path to the script that will send a message to MSTeams.
Here's an example script that sends a message to MSTeams:
#!/bin/bash
# Set the webhook URL for the MSTeams channel
WEBHOOK_URL="https://outlook.office365.com/webhook/..."
# Set the message to send to MSTeams
MESSAGE="Azure DevOps pipeline completed successfully for branch $CI_COMMIT_REF_NAME"
# Send the message to MSTeams
curl -X POST -H "Content-Type: application/json" -d "{\"text\":\"$MESSAGE\"}" $WEBHOOK_URL
Replace the WEBHOOK_URL variable with the webhook URL for your MSTeams channel. You can find the webhook URL by following these steps:
- Navigate to the MSTeams channel where you want to receive alerts.
- Click on the ellipsis (...) next to the channel name and select "Connectors."
- Click on "Configure" next to "Incoming Webhook."
- Give the webhook a name and upload an image if you want.
- Copy the webhook URL and save it.
Summary
In this article, we learned how to set up an Azure DevOps pipeline to build and deploy code from the master or main branch and receive alerts in an MSTeams channel whenever the pipeline completes. We covered the prerequisites, how to set up Azure DevOps pipeline, how to set up MSTeams channel, and how to integrate the two.