我正在嘗試按照鏈接中的步驟洗掉 Azure DevOps 分支。 https://docs.microsoft.com/en-us/rest/api/azure/devops/git/refs/update-refs?view=azure-devops-rest-4.1
注意:Branch 沒有任何關聯的策略/鎖。
我可以在 postman 中測驗 API 及其成功。但是,相同的 API 在 PowerShell 中不起作用。
我正在嘗試上傳 csv 檔案,其中列是“Branchname”、“OldObjectId”。
錯誤:遠程服務器回傳錯誤:(400) 錯誤請求
$FileData = Get-Content $filePath | Select -skip 1 | ConvertFrom-Csv -Header "BranchName","objectId"
## Processing Each Row of Excel Data
$FileData | ForEach-Object {
Write-Output " Deleting branch:$($_.BranchName)"
##Assigning "0000000000000000000000000000000000000000" to newObjectId makes branch to delete.
$body = @{
oldObjectId =$($_.objectId)
newObjectId = "0000000000000000000000000000000000000000"
name = $($_.BranchName)
}
$json= ConvertTo-Json @( $body ) -Depth 100
Write-Output $DeleteBranche_BaseURL
Write-Output $json
##Innvoking REST API to delete stale branch
$ADO_ADODeleteBranchesResponse = Invoke-RestMethod -Uri $DeleteBranche_BaseURL -Method POST -Headers $AzureDevOpsAuthenicationHeader -Body $json -ErrorAction Ignore
Write-Output #ADO_ADODeleteBranchesResponse
}
uj5u.com熱心網友回復:
您可以檢查請求的內容型別嗎?我-ContentType "application/json"在相同的請求中使用:
Invoke-RestMethod -Uri $PostUrl -Method Post -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $body
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/373759.html
標籤:混帐 电源外壳 分支 git 分支 azure-devops-rest-api
下一篇:無法將新的本地分支推送到遠程倉庫
