แก้ไข

แชร์ผ่าน


DeleteFiles@1 - Delete files v1 task

Delete folders, or files matching a pattern.

Delete files or folders. (The minimatch patterns will only match file paths, not folder paths).

Syntax

# Delete files v1
# Delete folders, or files matching a pattern.
- task: DeleteFiles@1
  inputs:
    #SourceFolder: # string. Source Folder. 
    Contents: 'myFileShare' # string. Required. Contents. Default: myFileShare.
    #RemoveSourceFolder: false # boolean. Remove SourceFolder. Default: false.
  # Advanced
    #RemoveDotFiles: false # boolean. Remove files starting with a dot. Default: false.
# Delete files v1
# Delete folders, or files matching a pattern.
- task: DeleteFiles@1
  inputs:
    #SourceFolder: # string. Source Folder. 
    Contents: 'myFileShare' # string. Required. Contents. Default: myFileShare.
    #RemoveSourceFolder: false # boolean. Remove SourceFolder. Default: false.
# Delete files v1
# Delete folders, or files matching a pattern.
- task: DeleteFiles@1
  inputs:
    #SourceFolder: # string. Source Folder. 
    Contents: 'myFileShare' # string. Required. Contents. Default: myFileShare.
# Delete Files v1
# Delete files or folders. (The minimatch patterns will only match file paths, not folder paths).
- task: DeleteFiles@1
  inputs:
    #SourceFolder: # string. Source Folder. 
    Contents: 'myFileShare' # string. Required. Contents. Default: myFileShare.

Inputs

SourceFolder - Source Folder
string.

If the source folder is empty, the task deletes files from the root folder of the repository as though $(Build.SourcesDirectory) was specified. If your build produces artifacts outside of the sources directory, specify $(Agent.BuildDirectory) to delete files from the build agent working directory.


Contents - Contents
string. Required. Default value: myFileShare.

The file/folder paths to delete. Supports multiple lines of minimatch patterns; each one is processed before moving onto the next line. Learn more about File matching patterns. 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
boolean. Default value: false.

Attempts to remove the source folder after attempting to remove Contents. If you want to remove the whole folder, set this to true and set Contents to *.


RemoveDotFiles - Remove files starting with a dot
boolean. Default value: false.

Deletes files starting with a dot. For example: .git and .dockerfile. Omits these files if it's not specified explicitly. For example: /.*. Learn more about minimatch.


Task control options

All tasks have control options in addition to their task inputs. For more information, see Control options and common task properties.

Output variables

None.

Remarks

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

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

Requirements

Requirement Description
Pipeline types YAML, Classic build
Runs on Agent, DeploymentGroup
Demands None
Capabilities This task does not satisfy any demands for subsequent tasks in the job.
Command restrictions This task runs using the following command restrictions: restricted
Settable variables This task has permission to set the following variables: Setting variables is disabled
Agent version 2.182.1 or greater
Task category Utility
Requirement Description
Pipeline types YAML, Classic build
Runs on Agent, DeploymentGroup
Demands None
Capabilities This task does not satisfy any demands for subsequent tasks in the job.
Command restrictions Any
Settable variables Any
Agent version 1.92.0 or greater
Task category Utility