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.
In this blog post, we will see how you can integrate Azure DevOps Project with a Slack Channel. Then, we will make a change in 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 for any Azure DevOps Pipelines related changes in your slack channel then you can read below blog post: How To Integrate Azure DevOps Pipelines With Slack Channel
Prerequisites
- To create subscriptions in a Slack channel for repository-related events, you must be a member of the Project Administrators group, or a team administrator.
Go to your Azure DevOps Project then click on Project Settings and then click on Permissions under General. On Right hand side under Groups tab you can find Project Administrators group. Click on Project Administrators group and then click on Add button to add your your account in to this group.
- To receive notifications, the 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 on Organization Settings on the bottom left hand side corner. Select Policies under Security and on the right hand side under Application connection policies, make sure that Third-party application access via OAuth is On.
Add Azure Repos app to Slack Workspace
Install Azure Repos Slack App to your Slack Workspace. After you click on this link, you will get below screen where you have to provide permission to Azure to access Slack Workspace. Select a slack channel where Azure will post notifications from Azure DevOps Project/Repo. Click on Allow to proceed further.
You can also link a Slack Channel from the channel itself. However, First you have to install this app. The Installation of Azure Repos Slack App is one time activity.
Once you have click on Allow, it will re-direct your session to the Slack App Installed on your device. If you do not have a Slack Desktop app installed, I will recommend to have it installed first.
Once the App is installed, you will see below message in the slack channel selected at the time of app installation. At this stage, we have just installed the app and have not connected Azure DevOps project with this slack Channel so notifications will not be showing in this slack channel as of now.
Connect Azure Repos App with Azure DevOps Project
Next Step is to connect your Azure Repos App with Azure DevOps Project or a specific repository. If you want to get notifications from all of the repositories under a project then better to go connect it with Azure Devops project.
For connecting 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 Sign in button to authenticate.
After you click on Sign in button, you can get Azure Repos Slack Integration page where you can verify the permissions requested and then click on 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>.
Login on Azure DevOps and click on the Project which you want to connect to this slack channel. Copy the URL from the address bar. If you want to connect to a specific repository then you will need to click on the repo and copy the URL of that Repo to connect.
Use below commands depending upon if you want to subscribe to a 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 few seconds to confirm the connection. You will get a message confirming that @user has added subscription Pull request created notification for Repository = Any in Project <Project Name>.
Now, We will create a Pull Request to see if it generate a notification in Slack Channel.
Once you click on Create on the Pull request, a notification will be generated in Slack Channel.
We have successfully tested the integraton 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 Service Hooks page.
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
It’s very convenient and useful to send the notifications from Azure DevOps directly to a slack channel where you can monitor the activities in Azure DevOps Project or Repo and also click on the URL to directly go to that project to check what changes were performed by your team member. In this blog post, I have shown only Pull request created notification configuration but using the service hooks in the project settings more triggers can be added.