通过PowerShell和TFS2015中的Rest API发送补丁请求

时间:2018-04-13 16:33:08

标签: powershell tfs

请在下面找到我在powershell中使用Patch方法创建的请求正文,以便在TFS中创建错误。但是无法创建错误和gettign消息“TF401320:找到字段的规则错误。错误代码:必需,HasValues,InvalidEmpty。”,“typeName”.....我也在这里附加了错误代码。

# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$pass)))

function CreateJsonBody
{
$value = @"
[
{
    "op": "add",
    "path": "/fields/System.Title",
    "value": "TestBug"
},
{
    "op": "add",
    "path": "/fields/Microsoft.VSTS.TCM.ReproSteps",
    "value": "Our authorization logic needs to allow for users"
},
{
    "op": "add",
    "path": "/fields/Microsoft.VSTS.Common.Priority",
    "value": "1"
},
{
    "op": "add",
    "path": "/fields/Microsoft.VSTS.Common.Severity",
    "value": "2 - High"
}
]
"@

return $value
}

$json = CreateJsonBody

$uri = "http://xxx-xxxxx-006:8080/tfs/xxx/xxxxx/_apis/wit/workItems/"+"$"+"bug/?api-version=2.0"
Write-Host $uri
$result = Invoke-RestMethod -Uri $uri -Method Patch -Body $json -Credential 
$credential  -ContentType "application/json-patch+json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

但没有得到回应。 获得以下错误

{
"$id": "1",
"innerException": null,
"message": "TF401320: Rule Error for field Found In. Error code: Required, HasValues, InvalidEmpty.",
"typeName": "Microsoft.TeamFoundation.WorkItemTracking.Server.RuleValidationException, Microsoft.TeamFoundation.WorkItemTracking.Server, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
"typeKey": "RuleValidationException",
"errorCode": 600171,
"eventId": 3200

}

请帮帮我。我已经编写了代码来为另一个帐户创建错误但不能在这里做。

0 个答案:

没有答案