16

According to https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&viewFallbackFrom=vsts&tabs=schema#checkout we can have this:

steps:
- checkout: self
  clean: true

But as far as I understand the documentation it only cleans the source tree, not all the build directories.

mark
  • 59,016
  • 79
  • 296
  • 580

1 Answers1

34

Workspace clean is probably what you want. You can define a workspace schema under the job and choose the resources to clean up.

Check here for more information about workspace.

  - job: myJob
    workspace:
      clean: outputs | resources | all # what to clean up before the job

runs

Julian
  • 33,915
  • 22
  • 119
  • 174
Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
  • 2
    I'm lost. It seems the correct answer, but when I open my YAML in AzureDevOps, I don't understand where do I add those lines. There is no `job` thing, only `trigger:` `pool:` `variables:` and then `steps:` with a "list" (whatever that is called in YAML) of `- task:`. – Pac0 Jul 29 '20 at 09:26
  • 1
    It goes at the same level as trigger, pool, variables – M. Cooper Aug 05 '20 at 18:18
  • 2
    @Pac0 Put `jobs:` at the top level, give it one or more `- job:` elements, and put your `steps:` one level down inside one of those `- job:`. – Jean-François Corbett Nov 04 '20 at 11:48
  • 1
    `job` is also an optional command. If you have only one, you may omit it and just include the next two lines ("workspace: \n clean: all") – jklemmack Dec 02 '20 at 04:14
  • How to clean it if we're using classic build pipeline? – liang Apr 07 '21 at 03:29
  • 1
    ah, found it here for the classic version https://stackoverflow.com/questions/62679610/azure-devops-clean-build-directory – liang Apr 07 '21 at 03:31
  • what are difference with those flags? – aj go Nov 16 '22 at 07:59