Azure DevOps:代表另一个用户创建评论

时间:2018-12-28 21:51:38

标签: azure-devops tfs-workitem workitem

我正在寻找一种方法来代表另一个用户(模拟另一个用户)向工作项添加评论。

        VssConnection connection = new VssConnection(new Uri(url), new VssClientCredentials());
        WorkItemTrackingHttpClient client = connection.GetClient<WorkItemTrackingHttpClient>();

        patchDocument.Add(
            new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path = "/fields/System.History",
                Value = "Sample comment 1"
            }
        );

        await client.UpdateWorkItemAsync(patchDocument, id);

1 个答案:

答案 0 :(得分:2)

要在Azure DevOps中对工作项创建评论(或代表某人进行更改),您需要在补丁文档中设置 System.ChangedBy 字段,还需要使用 bypassRules :true

        WorkItemTrackingHttpClient client = connection.GetClient<WorkItemTrackingHttpClient>();

        patchDocument.Add(
            new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path = "/fields/System.History",
                Value = "Sample comment 1"
            }
        );
        patchDocument.Add(
            new JsonPatchOperation()
            {
                Operation = Operation.Add,
                Path = "/fields/System.ChangedBy",
                Value = "user@onbehalfof.com" //can be valid user id (guid) or user email (domain\alias for onprem).
            });

        await client.UpdateWorkItemAsync(patchDocument, id, bypassRules:true);

此外,要能够设置 bypassRules:true -执行该操作的身份必须具有相应的权限:“绕过工作项更新的规则”