我试图通过 Azure DevOps Rest API 启用 "允许所有管道"。
$uri = "https://dev.azure.com/**/**/_apis/pipelines/pipelinePermissions/endpoint/" + $ID + "?api-version=5.1-preview.1"
$Allowpipelines = "[{
""allPipelines"": {
""authorizedBy"": null,
""authorizedOn"": null,
""authorized"": true,
""id"": ""$ID"",
""name"": ""Kubernetes"",
""type"": ""endpoint""
}
}]"
$output = Invoke-RestMethod -Uri $uri -Method Patch -Headers $AzureDevOpsAuthenicationHeader -ContentType "application/json"
echo $output
只有powershell给我以下错误。
Invoke-RestMethod : {"$id":"1","innerException":null,"message":"TF400898: An Internal Error Occurred.
Activity Id: 83a861fb-92ad-4f42-9007-452ca806f524.","typeName":"System.NullReferenceException, mscor
lib","typeKey":"NullReferenceException","errorCode":0,"eventId":0}
At line:2 char:14
+ ... Output= Invoke-RestMethod -Uri $uri -Method Patch -Header ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-R
estMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRest
MethodCommand
本体通过postman工作,但对于azure devops,我想通过Powershell让它工作。
经过一些故障排除,我发现了问题,我把一个后的json主体
谢谢你的时间和努力!
Finale代码。
$AzureDevOpsPAT = "****"
$OrganizationName = "****"
$ProjectName = "****"
$ID = "*****-*****-***-****-*******"
$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }
$baseUri = "https://dev.azure.com/$($OrganizationName)/$($ProjectName)/";
$uri = $baseUri + "/_apis/pipelines/pipelinePermissions/endpoint/"+ $ID + "?api-version=5.1-preview.1"
$Allowpipelines = @{
"allPipelines"= @{
"authorized"= "true"
"authorizedBy"= "null"
"authorizedOn"= "null"
}
"pipelines"= "null"
"resource"= @{
"id"= "${ID}"
"type"= "endpoint"
}
} | ConvertTo-Json -Depth 5
$output = Invoke-RestMethod -Uri $uri -Method Patch -Headers $AzureDevOpsAuthenicationHeader -Body $Allowpipelines -ContentType "application/json"