'How to exclude a repository from Cross Repo policies?

Cross repo policies in Azure DevOps are an improvement but currently they are a hammer and not a scalpel.

I am the Azure DevOps Administrator for my organisation and I have a request from a team building an IOS application with CocoaPods to allow pushing to master branch of a repository that holds the PodSpecs.

This is apparently how CocoaPods works and it is something they say they can't control through feature branches and pull requests.

While there is a pull request to CocoaPods to remove this ridiculous limitation, in the meantime I appear to be forced to remove protection from all master branches for all repos in the project cause there seems to be no way currently to specify:

Apply branch restrictions to the master branch of all current and future repositories in the project EXCEPT the repository named 'XYZ'

Does anyone out there know if I am reading this right or maybe has a solution?

Thank you.



Solution 1:[1]

It's not ideal but the best way to complete this currently seems to be allowing certain groups or users to bypass policies when pushing for the repo you want to exclude.

Solution 2:[2]

One way that works for specific repositories is to adjust this in the Security tab of the repository

Typically the Bypass policies when pushing has the value Not Set which means the cross-repo policy doesn't apply.

If you change the change this to Allow for say Contributors, then the developers can push changes directly to master.

Repository Security Tab

Solution 3:[3]

Cross Repo policies is designed to create policies which apply to all the repositories in the project, However, you can create a branch policy for each specific branch of a repository in azure devops.

So for your scenario, you can create branch policies for each branch instead of creating the cross repo policies which apply to all the repositories.

You can follow below steps to define a branch policies for a branch.

1, Select Repos > Branches to open the Branches page in the web portal of your project.

2, on the Branches page, click the 3 dots of the selected branch to protect > Select branch policies

enter image description here

3, Then configure your branch polices.

Branch policies created in this way only affect this specific branch for this repository.

For more information please check Improve code quality with branch policies

However you can submit a feature request(Click suggest a feature and choose Azure devops) for supporting repository exception in Cross Repo policies to Microsoft Development team. Hope them will consider it and implement this feature in the future.

Solution 4:[4]

Small tip for everyone who thinks it is the same for wiki repository.

Let's say you have a scenario where in cross repo policies you disable pushing directly to main branch. If you want to still be able to edit wiki pages directly from browser, logically thinking you should go to the repo that is the same name as the project, which is the actual wiki page, you go to security and enable bypass policies while pushing.

However this will never work, I have spent several hours trying to understand what do I miss. For wiki pages you have to do it directly on wiki page like this:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Parsonson
Solution 2 Paul Hatcher
Solution 3
Solution 4 donatasj87