CopyFiles@1 - Copy Files v1 task

Use this task to copy files from a source folder to a target folder using match patterns. (The match patterns will only match file paths, not folder paths).

Note

There is a newer version of this task available at CopyFiles@2.

Syntax

# Copy Files v1
# Copy files from source folder to target folder using minimatch patterns (The minimatch patterns will only match file paths, not folder paths).
- task: CopyFiles@1
  inputs:
    #SourceFolder: # string. Source Folder. 
    Contents: '**' # string. Required. Contents. Default: **.
    TargetFolder: # string. Required. Target Folder. 
  # Advanced
    #CleanTargetFolder: false # boolean. Clean Target Folder. Default: false.
    #OverWrite: false # boolean. Overwrite. Default: false.
    #flattenFolders: false # boolean. Flatten Folders. Default: false.

Inputs

SourceFolder - Source Folder
string.

Optional. The folder that contains the files you want to copy. If the folder is empty, then the task copies files from the root folder of the repo as though $(Build.SourcesDirectory) was specified.

If your build produces artifacts outside of the sources directory, specify $(Agent.BuildDirectory) to copy files from the directory created for the pipeline.


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

The file paths to include as part of the copy. This string supports multiple lines of match patterns.

For example:

  • * copies all files in the specified source folder.
  • ** copies all files in the specified source folder and all files in all sub-folders.
  • **\bin\** copies all files recursively from any bin folder.

The pattern is used to match only file paths, not folder paths. Specify patterns, such as **\bin\** instead of **\bin.

Use the path separator that matches your build agent type. For example, / must be used for Linux agents. More examples are shown below.


TargetFolder - Target Folder
string. Required.

The target folder or UNC path that will contain the copied files. You can use variables. Example: $(build.artifactstagingdirectory).


CleanTargetFolder - Clean Target Folder
boolean. Default value: false.

Optional. Deletes all existing files in the target folder before the copy process.


OverWrite - Overwrite
boolean. Default value: false.

Optional. Replaces the existing files in the target folder.


flattenFolders - Flatten Folders
boolean. Default value: false.

Optional. Flattens the folder structure and copies all files into the specified target folder.


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

There is a newer version of this task available at CopyFiles@2.

If no files match, the task will still report success. If a matched file already exists in the target folder, the task will report failure unless Overwrite is set to 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 Any
Settable variables Any
Agent version 1.91.0 or greater
Task category Utility

See also