收到一只叮咚
默认情况下,我们只能通过登录用户添加评论。但是,您可以使用 REST API 将评论添加到与另一个用户的讨论中,以更新启用System.ChangedBy字段的值bypassRules:以下样本供您参考:Param( [string]$baseurl = "http://server:8080/tfs/DefaultCollection", [string]$projectName = "ProjectName", [string]$workitemID = "26", [string]$user = "username", [string]$token = "token/Password")# Base64-encodes the Personal Access Token (PAT) appropriately$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))write-host $WorkitemTypefunction CreateJsonBody{ $value = @"[ { "op": "add", "path": "/fields/System.History", "value": "Comment here" }, { "op": "add", "path": "/fields/System.ChangedBy", "value": "user@oxxx.com" }]"@ return $value}$json = CreateJsonBody$uri = "$baseurl/$($projectName)/_apis/wit/workitems/$($workitemID)?bypassRules=true&api-version=2.2"Write-Host $uri$result = Invoke-RestMethod -Uri $uri -Method Patch -Body $json -ContentType "application/json-patch+json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}"value": "user@oxxx.com" 可以是其他用户的有效用户 ID (guid) 或用户电子邮件。