Integrate Azure Devops Repos with a Slack Channel

You can monitor your Azure DevOps Repositories and get notified in a Slack channel whenever code is pushed/checked in and whenever a pull request (PR) is created, updated, or a merge is attempted.

This blog post will show how you can integrate Azure DevOps Project with a Slack Channel. Then, we will change one of the Project Repos and create a Pull request to generate a notification in that Slack channel.

If you also want to get notified of any Azure DevOps Pipelines-related changes in your Slack channel, then you can read the blog post: How To Integrate Azure DevOps Pipelines With Slack Channel

Prerequisites

  • You must be a member of the Project Administrators group or a team administrator to create subscriptions in a Slack channel for repository-related events.

Go to your Azure DevOps Project, click on Project Settings, and click Permissions under General. On the right-hand side, under the Groups tab, you can find the Project Administrators group. Click on the Project Administrators group and then the Add button to add your account to this group.

Integrate Azure Devops Repos with a Slack Channel
Integrate Azure DevOps Repos with a Slack Channel
  • To receive notifications, Third-party application access via OAuth setting must be enabled for the organization.

Go to your Azure DevOps Organization using the link https://dev.azure.com/<your AzureDevOps Org Name>, then click Organization Settings in the bottom left-hand corner. Select Policies under Security, and on the right-hand side under Application connection policies, ensure that Third-party application access via OAuth is On.

Third-party application access via OAuth
Third-party application access via OAuth

STEP 1 – Add Azure Repos app to Slack Workspace

Install the Azure Repos Slack App in your Slack Workspace. After you click on this link, you will see the screen below, where you have to give Azure permission to access your Slack Workspace. Select a Slack channel where Azure will post notifications from the Azure DevOps Project/Repo. Click on Allow to proceed.

You can also link a Slack Channel from the channel itself. However, you first have to install this app. The Installation of the Azure Repos Slack App is a one-time activity.

Add Azure Repos app to Slack Workspace
Add Azure Repos app to Slack Workspace

Once you click on Allow, your session will be redirected to the Slack App Installed on your device. I recommend installing the Slack Desktop app first if you do not have one.

Once the App is installed, you will see the message below in the Slack channel selected at the time of app installation. At this stage, we have just installed the app and have not connected the Azure DevOps project with this Slack channel, so notifications will not be showing in this Slack channel as of now.

Add Azure Repos app to Slack Workspace
Add Azure Repos app to Slack Workspace

STEP 2 – Connect Azure Repos App with Azure DevOps Project/repo

The next step is to link your Azure Repos App with your Azure DevOps Project or a particular repository. If you want to receive notifications from all the repositories within a project, it’s better to connect it to the Azure DevOps project.

To connect a Slack Channel with Azure DevOps Project, Follow below steps:

  • Click on the Slack channel where you want to get Notifications posted by Azure DevOps.
  • Type /azrepos signin command and press enter.
Integrate Azure Devops Project or Repos with Slack Channel
Add Azure Repos app to Slack Workspace
  • Click on the Sign in button to authenticate.
Integrate Azure Devops Project or Repos with Slack Channel
Add Azure Repos app to Slack Workspace
  • After you click the Sign in button, you can access the Azure Repos Slack Integration page to verify the permissions requested. Then, click Accept to proceed.
Integrate Azure Devops Project or Repos with Slack Channel
Azure Repos Slack Integration
  • Copy the Code.
Integrate Azure Devops Project or Repos with Slack Channel
Azure Repos Slack Integration
  • Go back to the channel and then click on Enter Code. Paste the code to sign in.
Integrate Azure Devops Project or Repos with Slack Channel
Azure Repos Slack Integration
  • Now, you will get a message confirming that you are successfully signed in to Azure Repos as <your account name>.
Integrate Azure Devops Project or Repos with Slack Channel
Azure Repos Slack Integration
  • Log in to Azure DevOps and click on the Project you want to connect to this Slack channel. Copy the URL from the address bar. If you want to connect to a specific repository, click on the repo and copy the URL of that Repo to connect.
Integrate Azure Devops Project or Repos with Slack Channel
Azure Repos Slack Integration
  • Use the below commands depending upon if you want to subscribe to an Azure DevOps project or a specific Repo in Azure DevOps project.
    • To subscribe to Azure DevOps Project: /azrepos subscribe <AzureDevOps Project URL>
    • To subscribe to Azure DevOps Repo: /azrepos subscribe <AzureDevOps Repo URL>
Integrate Azure Devops Project or Repos with Slack Channel
Azure Repos Slack Integration
  • It will take a few seconds to confirm the connection. You will get a message confirming that @user has added a subscription Pull request created notification for Repository = Any in Project <Project Name>.
Integrate Azure Devops Project or Repos with Slack Channel
Azure Repos Slack Integration
  • Now, We will create a Pull Request to see if it generates a notification in the Slack Channel.
Integrate Azure Devops Project or Repos with Slack Channel
Azure Repos Slack Integration
  • Once you click on Create on the Pull request, a notification will be generated in the Slack Channel.
Integrate Azure Devops Project or Repos with Slack Channel
Azure Repos Slack Integration
  • We have successfully tested the integration by creating a pull request. There is a service hook created under Project Settings. You can add more triggers to get the notification in the Slack channel by clicking on + Sign from the Service Hooks page.
Integrate Azure Devops Project or Repos with Slack Channel
Azure Repos Slack Integration

Useful Commands:

To check the Subscriptions:

/azrepos subscriptions

To unsubscribe from all notifications:

/azrepos unsubscribe all <project url>

To Sign out from Azure Repos organization:

/azrepos signout

Conclusion

Sending notifications from Azure DevOps directly to a Slack channel is a convenient way to monitor activities in your Azure DevOps project or repository. You can also click on the URL provided to access the project and review the changes made by your team members. This blog post demonstrated how to configure notifications for pull request creation, but you can add more triggers using service hooks in the project settings.

Leave a Comment