You can monitor Azure DevOps Repos 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: Integrate Azure DevOps Pipelines With Slack Channel.
Contents
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.
- 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 Azure DevOps 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.
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 below screen, 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.
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.
Step 2: Connect Azure Repos App with Azure DevOps Project/repo
The next step is to link Azure Repos App with 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.
- Click on the Sign-in button to authenticate.
- 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.
- Copy the Code.
- Go back to the channel and then click on Enter Code. Paste the code to sign in.
- Now, you will get a message confirming that you are successfully signed in to Azure Repos as <your account name>.
- 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.
- 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>
- 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>.
- Now, We will create a Pull Request to see if it generates a notification in the Slack Channel.
- Once you click on Create on the Pull request, a notification will be generated in the Slack Channel.
- 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.
Related 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.