HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Azure DevOps Clean after pipeline run

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
afterazuredevopspipelinerunclean

Problem

I have self-hosted build agents using Azure DevOps. We have the clean flag in the checkout step, however we run out of space sometimes.

What is the preferred way of cleaning the agents' work directories?

The problem is, that the clean process is in the beginning of a pipeline, and leaves everything behind. This is even worse if we have two parallel builds. (First clean then clones the repo, then the second cleans and clones the repo, then first build, then there is no space for the second build). Unless the first build is scheduled again, the build outputs stays on the agent.

We tried to schedule a deletion task every day, but it doesn't solve our problems.

We tried to add a script at the end of our yaml file that cleans the working dir. Is it recommended?

- powershell: Remove-Item $(Pipeline.Workspace)/** -Force
      displayName: Clean after publish


Also it would be great if we could clean up even if the build fails, or someone cancels it midway.

Solution

- task: DeleteFiles@1
displayName: 'clean *'
inputs:
SourceFolder: '$(Pipeline.Workspace)'
Contents: '**/*'
RemoveDotFiles: true
condition: always()


will clean everything in '$(Pipeline.Workspace)/notClean/allClean'.

Context

StackExchange DevOps Q#15039, answer score: 2

Revisions (0)

No revisions yet.