I am trying to update branch policy of a branch in Azure DevOps repository. I am trying to do it using Rest API calls following documentation from here.
When I run this from Postman, the request completes successfully with status code '200 OK'. Upon checking the status of branch policy in Azure DevOps, I am able to see that the option "Limit merge types" is "on", however, no checkbox is checked under "Allowed merge types:".
Here is json payload which I used.
POST https://dev.azure.com/{{Org}}/{{ProjectName}}/_apis/policy/configurations?api-version=7.0
{
"isEnabled": true,
"isBlocking": true,
"type": {
"id": "fa4e907d-c16b-4a4c-9dfa-4916e5d171ab"
},
"settings": {
"useSquashMerge": true,
"scope": [
{
"refName": "refs/heads/test_branch_for_policy",
"matchKind": "exact",
"repositoryId": "11223344-480x-4u1h-x16k-112233445566"
}
]
}
}
It seems "useSquashMerge": true
under settings
is not being considered.
TL;DR use allowSquash
instead of useSquashMerge
.
This works when using Azure DevOps Services (cloud), not sure about Azure DevOps Server (hosted).
Doing some research, I was able to find in Automating Branch Policies the right settings to configure the Limit Merge Types
section of the branch policy:
useSquashMerge
allowNoFastForward
allowSquash
allowRebase
allowRebaseMerge
All settings work in Azure DevOps Services except useSquashMerge
. I couldn't find much information about it, but it seems to be used in TFS / Azure DevOps Server - see Merge strategy policy settings inconsistent.
Executing the following code request on Postman:
https://dev.azure.com/my-organization/my-project/_apis/policy/configurations?api-version=7.0
Request body:
{
"isEnabled": true,
"isBlocking": true,
"type": {
"id": "fa4e907d-c16b-4a4c-9dfa-4916e5d171ab"
},
"settings": {
"allowSquash": true,
"useSquashMerge": true,
"allowRebaseMerge": false,
"allowRebase": false,
"allowNoFastForward": false,
"scope": [
{
"repositoryId": "1xxxx516-aaaa-4ce4-xxxx-d56abbbbb6ec",
"refName": "refs/heads/main",
"matchKind": "exact"
}
]
}
}
Response:
{
"createdBy": {
"displayName": "Some user",
"url": "https://spsprodeus21.vssps.visualstudio.com/xxxx-xxxx-xxxx-xxxx-xxxx/_apis/Identities/xxxx-xxxx-xxxx-xxxx-xxxx",
"_links": {
"avatar": {
"href": "https://dev.azure.com/my-organization/_apis/GraphProfile/MemberAvatars/aad.xxxxxx"
}
},
"id": "7af0d439-aa9b-40cf-93a4-fb725b0694a7",
"uniqueName": "john@hotmail.com",
"imageUrl": "https://dev.azure.com/my-organization/_api/_common/identityImage?id=xxxx-xxxx-xxxx-xxxx-xxxx",
"descriptor": "aad.xxxxxx"
},
"createdDate": "2024-07-13T13:18:59.5387814",
"isEnabled": true,
"isBlocking": true,
"isDeleted": false,
"settings": {
"useSquashMerge": true,
"allowNoFastForward": false,
"allowSquash": true,
"allowRebase": false,
"allowRebaseMerge": false,
"scope": [
{
"refName": "refs/heads/main",
"matchKind": "Exact",
"repositoryId": "1xxxx516-aaaa-4ce4-xxxx-d56abbbbb6ec"
}
]
},
"isEnterpriseManaged": false,
"_links": {
"self": {
"href": "https://dev.azure.com/my-organization/xxxx-xxxx-xxxx-xxxx-xxxx/_apis/policy/configurations/75"
},
"policyType": {
"href": "https://dev.azure.com/my-organization/xxxx-xxxx-xxxx-xxxx-xxxx/_apis/policy/types/xxxx-xxxx-xxxx-xxxx-xxxx"
}
},
"revision": 1,
"id": 75,
"url": "https://dev.azure.com/my-organization/xxxx-xxxx-xxxx-xxxx-xxxx/_apis/policy/configurations/75",
"type": {
"id": "xxxx-xxxx-xxxx-xxxx-xxxx",
"url": "https://dev.azure.com/my-organization/xxxx-xxxx-xxxx-xxxx-xxxx/_apis/policy/types/xxxx-xxxx-xxxx-xxxx-xxxx",
"displayName": "Require a merge strategy"
}
}
Note: