'Is possible to create an Azure DevOps Pull Request policy to set delete after merging automatically when setting auto-complete?

In the company I'm working we use Azure DevOps and we have a core repository with a huge amount of branches.

In order to maintain this repository clearer as possible I am looking to set an Azure DevOps PR policy (by Azure CLI) to automatically set every PR with 'Delete {source-branch} after merging', but obviously if having an option to specify which branches we do not desire to be deleted after merging

I had look at MS docs about Azure CLI PR options but I do not see this one https://docs.microsoft.com/en-us/cli/azure/repos/pr?view=azure-cli-latest



Solution 1:[1]

You can set the ForcePush rights on all the feature branches for given repository like this:

tf git permission /allow:ForcePush /group:$groupContributors /collection:$collection /teamproject:$teamproject /branch:feature /repository:$repo    

$collection = "Base URl of your Azure DEVOPS organization"
$teamproject = "Name of the Azure devops Project"
$repo = "Name of the Azure repo under the teamproject"
$groupContributors = "group of the users for which  the ForcePush permission will be applied to. Typically the default out of the box SomeAzureDEVOPSProject\Contributors group"

Then the other standard (non admin level) users from your Azure devops project team will be able to delete the source branch on pull request merge.

You need to run the command under VISUAL STUDIO DEVELOPERS PROMPT ( so the tf command is available and on the path, it is possible to run it from your local machine against the Azure ( a sso authentication menu box will pop up)

see also:

https://docs.microsoft.com/en-us/azure/devops/repos/tfvc/git-permission-command?view=azure-devops

and

https://docs.microsoft.com/en-us/dotnet/api/microsoft.teamfoundation.sourcecontrol.webapi.gitrepositorypermissions?view=azure-devops-dotnet

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 user3212757