Azure开发PowerShell任务,当管道失败时创建错误,错误页面未找到



为REST API设置URL以创建新的工作项

$uri = "https://dev.azure.com/Abc/Def/_apis/wit/workitems/$bug?api-version=6.1-preview.3" 
echo $uri
# Set the personal access token (PAT) for authentication
$pat = "U2hyayuty43f4y32tfytf23ytf"
$headers = @{
"Authorization" = "Basic $pat"
"Content-Type" = "application/json-patch+json"
}
# Create the JSON payload for the new defect work item
$defectPayload = @"
[
{
"op": "add",
"path": "/fields/System.Title",
"from": null,
"value": "Test of REST functionality"
},
{
"op": "add",
"path": "/fields/System.State",
"from": null,
"value": "New"
}
]
"@

# Create the new defect work item
Invoke-RestMethod -Uri $uri -Headers $headers -Method Post -Body ($defectPayload|ConvertTo-Json)

它的工作在邮差,但在azure管道失败与错误:未找到页面。

因为这里的$bug想要成为一个变量:

$uri = "https://dev.azure.com/Abc/Def/_apis/wit/workitems/$bug?api-version=6.1-preview.3" 

试试这个:

$uri = 'https://dev.azure.com/Abc/Def/_apis/wit/workitems/$bug?api-version=6.1-preview.3'