Question: In the Azure DevOps portal, I select a pipeline, then the [...] menu, then Delete.

I see a message asking:

> 
> Are you sure? This action cannot be undone. This will permanently
>  delete the pipeline 'vt3e (1)'. Deletion includes all builds and
>  associated artifacts.
> 
> 
> 

I type in the pipeline name and click OK but the pipeline does not delete.

I have waited some hours.

**[Update]**

F12 in Chrome shows an error in the console:

> 
> ms.vss-build-web.common-library.\_\_y\_\_CePsj5f5zdcIK.min.js:18 Error:
>  One or more builds associated with the requested pipeline(s) are
>  retained by a release. The pipeline(s) and builds will not be deleted
> 
> 
> 

**[Update]**

I am trying to follow the answer given by David D, but when I go to delete a release I get a message

> 
> VS402946: 'Release-8' cannot be deleted as it is currently deployed on
>  stage(s) Stage 1.
> 
> 
> 

**[update]**

[The issue is logged at Microsoft](https://developercommunity.visualstudio.com/content/problem/324411/deleting-a-build-pipeline-does-not-work.html)

Answer: 
I came on the same problem last week and I updated a script from someone to work with the 5.1 API. This script will run over all builds that are retained by a release pipeline. You will need some tweaking of you don't want that all your builds are removed from releases.

```
$tfsServerURL = "https://dev.azure.com/{organisation}"
$TFSProject = "{project}"

$AzureDevOpsPAT = "{token}"
$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)"))}

#Set to $true to update builds by settingretainingByRelease= false
$CorrectError = $true

$URL = "$($tfsServerURL)/$($TFSProject)"
Write-Output $URL
#Get all builddefinitions in Project
$Buildefinitions = (Invoke-RestMethod -Uri ($URL + '/_apis/build/definitions?api-version=5.1') -Method GET -UseDefaultCredentials -Headers $AzureDevOpsAuthenicationHeader).value

foreach($Builddefiniton in $Buildefinitions)
{
    Write-Output "Searching in $($Builddefiniton.name) with id $($Builddefiniton.id)"
    #Get Builds with keepforever = false and retainedByRelease = true

    $Builds = (Invoke-RestMethod -Uri ($URL + '/_apis/build/builds?definitions=' + $Builddefiniton.id + '&api-version=5.1') -Method GET -UseDefaultCredentials -Headers $AzureDevOpsAuthenicationHeader).value | where {$_.keepForever -eq $False -and $_.retainedByRelease -eq $true}

    #Get releases linked to the build

    foreach ($build in $Builds)
    {
        If ($CorrectError)
        {
            Invoke-RestMethod -Uri ($URL + '/_apis/build/builds/'+ $build.id + '?api-version=5.1') -Method Patch -Body (ConvertTo-Json @{"retainedByRelease"='false'}) -UseDefaultCredentials -Headers $AzureDevOpsAuthenicationHeader -ContentType "application/json" | Out-Null
            Write-Output "`tFixed"
        }
    }
}

```

The PowerShell script will first fetch all build pipelines, then fetch all builds that are not kept infinitely and are retained by a release. If the CorrectError is set to true the script will then try to switch the retainedByRelease flag to false.

After I ran this script I was able to remove my build pipeline.
You just need to click on three dots menu button and select delete then it will make sure that you know what you are actually doing, check the "
Automatically cancel any in-progress release deployments" and remove it

[![enter image description here](https://i.stack.imgur.com/f9dZw.png)](https://i.stack.imgur.com/f9dZw.png)