azure-devops - Azure 开发运营 : create a comment on behalf of another user

标签 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);

最佳答案

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

        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 - 执行操作的身份必须具有适当的权限:“绕过工作项更新规则”

关于azure-devops - Azure 开发运营 : create a comment on behalf of another user,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53964647/

相关文章:

tfs - 在 TFS 2010 中打开 WI 附件而不先下载它

c# - 列出 TFS 项目中使用的 'areas'

css - 更改工作项标签的样式

azure-devops - 如何使用服务主体将角色分配给另一个服务主体

azure - 如何从 Azure DevOps 发布管道将 docker 容器部署到 Ubuntu 服务器实例?

tfs - 在Team Foundation Server 2008中使用区域和迭代

tfs - TFS 2010 中缺少 "Requirement"工作项类型

azure - 合并时触发 Azure Pipeline

azure-devops - Azure DevOps 每晚构建 - schedules\cron 语法

merge - 如何选择要合并附加到工作项的变更集?