I am trying to add a new branch to existing set of release triggers. I am able to view the URL content for the release definition however PATCH operation is failing with the following error. Could someone assist me in reviewing and refining my code?
"innerException": null, "message": "VS403051: Could not delete pipeline with ID 515 because it was not found. Specify a valid ID | and try again.", "typeName": "Microsoft.VisualStudio.Services.ReleaseManagement.Data.Exceptions.DeletedReleaseDefinitionNotFoundException
Code for reference
$releaseDefinitionId = "515"
$pat = "test_pat_token"
# Define the continuous deployment trigger
$continuousDeploymentTrigger = @{
triggerType = "continuousIntegration"
settingsSourceType = "definition"
branchFilters = @(
"+refs/heads/develop"
)
}
# Convert the continuous deployment trigger to JSON format
$body = @{
triggers = @(
$continuousDeploymentTrigger
)
} | ConvertTo-Json
# Define the REST API URL
$url = "https://vsrm.dev.azure.com/org/project/_apis/release/definitions/$($releaseDefinitionId)?api-version=7.1-preview.4"
# Invoke the REST API to update the release definition
Invoke-RestMethod -Uri $url -Method Patch -Headers @{
Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($pat)"))
} -Body $body -ContentType "application/json"
To update the release definition, you should use the REST API "Definitions - Update" with the
PUTmethod.You first need to call the API "Definitions - Get" to get the response body of the release definition.
Update the response body by adding the new branch filter to the CD trigger.
Finally, you can call the API "Definitions - Update" with the new body to update the release definition.
Below is a PowerShell script sample as reference.