I am trying to disable a build pipeline on Azure DevOps using Powershell but getting an error
Script:
$project = "<Project-Name>"
$organization = "<Org-Name>"
$pat = "<PAT>"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($pat)"))
$headers = @{
Authorization = "Basic $base64AuthInfo"
"Content-Type" = "application/json"
}
$pipelineDetailsUrl = "https://dev.azure.com/$organization/$project/_apis/pipelines/<ID>?api-version=6.0"
$pipelineDetails = Invoke-RestMethod -Uri $pipelineDetailsUrl -Method Get -Headers $headers
$pipelineDetails.configuration.designerJson.queueStatus = "disabled"
$body = $pipelineDetails | ConvertTo-Json -Depth 10
Invoke-RestMethod -Uri $pipelineDetailsUrl -Method Put -Headers $headers -Body $body -ContentType "application/json"
However I am getting below error
Invoke-RestMethod : {"count":1,"value":{"Message":"The requested resource does not support http method ‘PUT’."}}
3
Answers
Update
Found the problem, it was the endpoint I was trying to hit, instead of
use
The error message says that the Azure DevOps REST API does not support the HTTP PUT method for the endpoint you’re using. To disable a build pipeline, you should use the correct endpoint and method supported by the Azure DevOps API. Like this:
The script first retrieves the pipeline details using a GET request.
It then modifies the enabled property of the pipeline configuration to false.
Finally, it sends a PUT request with the updated pipeline details to disable the pipeline.
The right endpoints to use are the following:
Example