gpt4 book ai didi

azure - 通过 REST API Powershell 脚本检查 "Allow all pipelines"

转载 作者:行者123 更新时间:2023-12-03 05:36:21 25 4
gpt4 key购买 nike

我正在尝试通过 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 主体后面添加了一个

感谢您的时间和精力!

结局代码:

$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"

关于azure - 通过 REST API Powershell 脚本检查 "Allow all pipelines",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62248746/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com