Azure DevOps: create a comment on behalf of another user

前端 未结 1 1201
野性不改
野性不改 2021-01-14 07:12

I\'m looking for a way to add a comment to a work item on behalf of another user (impersonate another user).

        VssConnection connection = new VssConnec         


        
相关标签:
1条回答
  • 2021-01-14 07:47

    To create a comment (or make a change on behalf of someone) on a work item in Azure DevOps you need to set System.ChangedBy field in the patch document and also use 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);
    

    Also, to be able to set bypassRules:true - the identity that performs the operation must have the appropriate permission: "Bypass rules on work item updates"

    0 讨论(0)
提交回复
热议问题