Del via


Delete Files task

TFS 2017 | TFS 2015

Use this task to delete files or folders from the agent working directory.

Demands

None

Arguments

Argument Description
SourceFolder
Source Folder
(Optional) Folder that contains the files you want to delete. If you leave it empty, the deletions are done from the root folder of the repository (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.
Contents
Contents
(Required) File/folder paths to delete. Supports multiple lines of minimatch patterns; each one is processed before moving onto the next line. More Information.
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 and folders in any sub-folder named temp.
  • **/temp* deletes any file or folder with a name that begins with temp.
  • !(*.vsix) deletes all files in the root folder that do not have a .vsix extension.
RemoveSourceFolder
Remove SourceFolder
(Optional) Attempt to remove the source folder after attempting to remove Contents.
Default value: false.
If you want to remove the whole folder, set this to true and set Contents to *.

Advanced

RemoveDotFiles
Remove DotFiles
(Optional) Delete files starting with a dot (.git, .dockerfile). Omits these files if it's not specified explicitly (for example, '/.*'). More information.
Default value: false.

Examples

Delete several patterns

This example will delete some/file, all files beginning with test, and all files in all subdirectories called bin.

steps:
- task: DeleteFiles@1
  displayName: 'Remove unneeded files'
  inputs:
    contents: |
      some/file
      test*
      **/bin/*

Delete all but one subdirectory

This example will delete some/one, some/three and some/four but will leavesome/two.

steps:
- task: DeleteFiles@1
  displayName: 'Remove unneeded files'
  inputs:
    contents: |
      some/!(two)

Delete using brace expansion

This example will delete some/one and some/four but will leave some/two and some/three.

steps:
- task: DeleteFiles@1
  displayName: 'Remove unneeded files'
  inputs:
    contents: |
      some/{one,four}

Delete files starting with a dot

This example will delete all .txt files. Files starting with a dot will be deleted as well.

steps:
- task: DeleteFiles@1
  displayName: 'Remove unneeded files'
  inputs:
    contents: |
      /some/*.txt
    removeDotFiles: true

Open source

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

FAQ

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

A: See:

Q: I'm having issues with publishing my artifacts. How can I view the detailed logs?

To enable detailed logs for your pipeline:

  1. Edit your pipeline and select Variables
  2. Add a new variable with the name System.Debug and value true
  3. Save

Q: Which variables are available to me?

A: $(Build.SourcesDirectory) and $(Agent.BuildDirectory) are just few of the variables you can use in your pipeline. Variables are available as expressions or scripts.

See Define variables, predefined variables, and Classic release and artifacts variables to learn about the different types of variables.

Q: Task allows me to publish artifacts in deployment job in yaml pipeline, but I am not able to use it in downstream pipeline?

A: Deployment jobs do not have the context of source branches and are hence not appropriate for publishing artifacts. They have been primarily designed to consume artifacts. A workaround would be to isolate that logic into a separate job (with dependencies on your deployment jobs).

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.

My NuGet push task is failing with the following error: "Error: unable to get local issuer certificate". How can I fix this?

This can be fixed by adding a trusted root certificate. You can either add the NODE_EXTRA_CA_CERTS=file environment variable to your build agent, or you can add the NODE.EXTRA.CA.CERTS=file task variable in your pipeline. See Node.js documentation for more details about this variable. See Set variables in a pipeline for instructions on setting a variable in your pipeline.

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.