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.