我正在创建一个脚本(在python中),以通过以下示例在Azure DevOps中设置分支策略:https://docs.microsoft.com/en-us/rest/api/azure/devops/policy/configurations/create?view=azure-devops-rest-5.1#approval-count-policy
代码如下:
policyClient = connection.clients.get_policy_client()
jsonSettings = {
'requiredReviewerIds': [
'2ad77975-c0fc-471a-a161-3452b1ec842d',
'cf0931e8-2aa6-42b3-9597-3522689c5190'
],
'scope': [
{
'refName': 'refs/heads/master',
'matchKind': 'Exact',
'repositoryId': '70c7c55c-8fd0-44c4-a175-db7093e38ff2'
}
]
}
policyConfiguration = PolicyConfiguration(
is_enabled=True,
is_blocking=True,
settings=json.dumps(jsonSettings)
)
policyClient.create_policy_configuration(configuration=policyConfiguration,project="demo")但是,响应是:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/azure/devops/released/policy/policy_client.py", line 46, in create_policy_configuration
content=content)
File "/usr/local/lib/python3.7/site-packages/azure/devops/client.py", line 104, in _send
response = self._send_request(request=request, headers=headers, content=content, media_type=media_type)
File "/usr/local/lib/python3.7/site-packages/azure/devops/client.py", line 68, in _send_request
self._handle_error(request, response)
File "/usr/local/lib/python3.7/site-packages/azure/devops/client.py", line 256, in _handle_error
raise AzureDevOpsClientRequestError(wrapped_exception.message)
azure.devops.exceptions.AzureDevOpsClientRequestError: Error setting value to 'Settings' on 'Microsoft.TeamFoundation.Policy.WebApi.PolicyConfiguration'.我有什么地方做错了吗?
感谢河
发布于 2019-10-11 16:48:47
# Create policy Client
policyClient = connection.clients.get_policy_client()
### Master branch minimum reviewer
policyMasterBranchMinimumReviewersConfiguration = PolicyConfiguration(
is_enabled=True,
is_blocking=True,
settings={
"allowDownvotes": False,
"creatorVoteCounts": False,
"minimumApproverCount": 2,
"resetOnSourcePush": False,
"scope": [
{
"matchKind": "Exact",
"refName": "refs/heads/master",
"repositoryId": None
}
]
},
type= {
"displayName": "Minimum number of reviewers",
"id": "fa4e907d-c16b-4a4c-9dfa-4906e5d171dd",
"url": "https://devops.momenta.works/Momenta/beedef84-314a-4255-833b-405409b7526c/_apis/policy/types/fa4e907d-c16b-4a4c-9dfa-4906e5d171dd"
},
)
policyClient.create_policy_configuration(configuration=policyMasterBranchMinimumReviewersConfiguration,project="demo")如上所示,我们不需要为设置做json.dumps。
https://stackoverflow.com/questions/58316187
复制相似问题