Skip to the content.

Back to Overview

Guidance for Post Build Cleanup and YAML Pipelines

For some time now we have been receiving feedback about issues with Post Build Cleanup and YAML pipelines, and we have investigated how to fix these. However, the way pipeline tasks work prevents us from really fixing the problems. Thus, there will never be a version of Post Build Cleanup that fully supports YAML, and here is why (if you are not interested in the backgroun, go down to Recommendations for YAML pipelines):

Why the task is not working

Post Build Cleanup relies on two pieces of information:

Since YAML supports working with multiple repositories (unlike classic), these options have been separated into the clean property of the checkout step, which cleans one specific repository folder on the agent, and the clean property of the workspace element of a job, which cleans the binaries directory (i.e., $(Build.BinariesDirectory), e.g., /agent/work/1/b) when set to outputs, the sources directory (i.e., $(Build.SourcesDirectory), e.g., /agent/work/1/s) when set to resources, or the pipeline workspace (i.e., $(Pipeline.Workspace), e.g., /agent/work/1) when set to all.

Clean Settings in Classic Pipelines

When running a YAML pipeline, Azure DevOps only sets the values mentioned above as follows:

What happens when the task runs in a YAML pipeline

Due to the aforementioned behavior of the variables and API responses, there can be multiple different behaviors of the Post Build Cleanup task:

Recommendations for YAML pipelines

Our recommendation depends on the number of repositories and your personal liking:

Only one repository in the pipeline

If you only need to clone one repository (the self repository) and you are willing to configure the cleanup behavior outside of your YAML file in the pipeline UI, you can continue using the Post Build Cleanup task in the newest version. To configure the cleanup behavior, edit your YAML pipeline in the browser, open the pipeline editor context menu (the three dots in the upper right corner), and select Triggers. Then click on the YAML tab, select the Get sources step on the left, set Clean to true and specify the required Clean options.

All other cases

In all other cases where you need multiple repositories and/or only want to configure the pipeline through the YAML file itself, you must use a custom script to do the cleanup steps. We have put together a steps template that you can add at the end of your pipeline for every repository you want to clean. It executes the same logic that Post Build Cleanup executes.