Andrew
Andrew

Reputation: 737

Azure Pipeline runs not automatically deleting

We have two build YAML pipelines to run tests on TFS one for front-end and one for back-end tests. We use two self-hosted windows agents to run these builds and we are on Azure DevOps Server 2020. Ever since we started running the pipeline we noticed our TFS database size ballooning up. We've tried editing our retention settings to only keep the most recent builds but they are still saved no matter what we change.

Below are our retention settings:

Collection Settings

enter image description here

Project Pipeline Settings

enter image description here

Project Pipeline Release Retention:

enter image description here

EDIT: Test Retention Settings:

enter image description here

END EDIT

Our YAML pipelines don't have any specific retention settings so my understanding would be that it defaults to the project pipeline settings. However, this doesn't seem to be the case. We have runs that go as far back as November, which is when we first created the pipelines. I can also manually check which builds are and aren't retained:

Example of retained build enter image description here enter image description here

Example of not retained build enter image description here enter image description here

However, these runs are just never getting deleted. Is my understanding of how retention works just incorrect and the builds shouldn't be getting automatically deleted by TFS? Or do I need to change my Azure DevOps settings somehow to automatically delete the builds once the retention settings no longer apply to it?

It's also worth mentioning we do have a release pipeline, although we've been experiencing these problems since way before we created it and the release pipeline only has dependencies on master but no feature runs are getting deleted either.

I did find this SO post that seems to only apply to classic UI pipeline editor. Is there a way I can apply this to my YAML pipeline?

Edit 2

So I did make some more progress on this. I wrote a script that would delete all the runs that weren't held by retention settings:

$token = "{PAT}"
$url="https://{instance}/{collection}/{project}/_apis/build/builds/?api-version=6.0"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))

$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json

ForEach( $build in $response.value )
{
    if ((-not $build.keepForever) -and (-not $build.retainedByRelease)) {
        $url="https://{instance}/{collection}/{project}/_apis/build/builds/$($build.id)?api-version=6.0"
        $deleteResponse = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Delete -ContentType application/json
        Write-Host "Deleted" $url
    }
} 

This deletes all the runs just fine. However, from what I can tell in the docs, this should happen automatically by TFS. Are there any event log sources I could filter for or any specific times of day to check that may lead me to where the actual deletion of the runs should be taking place?

Upvotes: 4

Views: 4263

Answers (1)

DigCamara
DigCamara

Reputation: 5568

It seems your problem was fixed in the Azure DevOps 2020.0.1 Patch 2 Release. I recommend looking at this thread in detail to see whether the solution applies in your case.

Upvotes: 1

Related Questions