Friday 30 April 2021

Get Policy Availability in BitBucket Repo to Have a Build (Azure DevOps Build etc.) Validating a Pull Request

 You can setup Build pipelines in BitBucket itself or even Azure DevOps builds to validate an incoming pull request to a stable branch such as master/main. You might want to setup some KPIs to validate availability of such build for PR validation. For such requirements you may have to obtain data from BitBucket API to check if a build validation policy exists for the stable branches in your repos. Let's see how we can get such data from BitBucket APIs.

As the first step you need to have a App Password (token) created for you in BitBucket to enable you to access APIs. You can do this in your account settings App Passwords section. You have to allow Admin access to reports to obtain the necessary data.


You can use this information and query for repositories in your BitBucket as follows. Below sample call is from postman but you can use any scripting language like PowerShell or try to utilize Power BI to call the REST API to obtain data and make it more visual.

https://api.bitbucket.org/2.0/repositories/{workspacename}


Once you have the repository names you would be able to get the branch restrictions applied in each repo as follows. From the pattern you can identify the branches where the restrictions are applied.

https://api.bitbucket.org/2.0/repositories/{workspacename}/{reponame}/branch-restrictions



No comments:

Popular Posts