Delete Files task

Azure Pipelines | Azure DevOps Server 2019 | TFS 2018 | TFS 2017 | TFS 2015.3

Use this task in a build or release pipeline to delete files or folders from the agent working directory.



YAML snippet

# Delete files
# Delete folders, or files matching a pattern
- task: DeleteFiles@1
    #SourceFolder: # Optional
    #Contents: 'myFileShare' 
    #RemoveSourceFolder: # Optional


Argument Description
Source Folder

Folder that contains the files you want to delete. If you leave it empty, the deletions are done from the root folder of the repo (same as if you had specified $(Build.SourcesDirectory)).

If your build produces artifacts outside of the sources directory, specify $(Agent.BuildDirectory) to delete files from the build agent working directory.


Specify minimatch pattern filters (one on each line) that you want to apply to the list of files to be deleted. For example:

  • **/* deletes all files and folders in the root folder.
  • temp deletes the temp folder in the root folder.
  • temp* deletes any file or folder in the root folder with a name that begins with temp.
  • **/temp/* deletes all files in any sub-folder named temp.
  • **/temp* deletes any file or folder with a name that begins with temp.
  • **/temp/* deletes files in any sub-folder that begins with the name temp.
Control options

Open source

This task is open source on GitHub. Feedback and contributions are welcome.

Q & A

Q: What's a minimatch pattern? How does it work?

A: See:

Q: I'm having problems. How can I troubleshoot them?

A: Try this:

  1. On the variables tab, add system.debug and set it to true. Select to allow at queue time.

  2. In the explorer tab, view your completed build and click the build step to view its output.

The control options arguments described above can also be useful when you're trying to isolate a problem.

Q: How do variables work? What variables are available for me to use in the arguments?

A: $(Build.SourcesDirectory) and $(Agent.BuildDirectory) are just a few of the variables you can use. Variables are available in expressions as well as scripts; see variables to learn more about how to use them. There are some predefined build and release variables you can also rely on.

Do I need an agent?

You need at least one agent to run your build or release.

I'm having problems. How can I troubleshoot them?

See Troubleshoot Build and Release.

I can't select a default agent pool and I can't queue my build or release. How do I fix this?

See Agent pools.

I use TFS on-premises and I don't see some of these features. Why not?

Some of these features are available only on Azure Pipelines and not yet available on-premises. Some features are available on-premises if you have upgraded to the latest version of TFS.