How to copy files from multiple folders on Azure DevOps CI?

Viewed 8691

In my yaml config file for Azure DevOps CI, I have a CopyFiles@2 task in order to stage files for PublishBuildArtifacts. I want to (1) copy specific files from the root of my source directory, and (2) all the files from a specific folder. I can copy the specific files successfully, but when I add the line for the specific folder, it fails. Here is the yaml snippet:

- task: CopyFiles@2 inputs: sourceFolder: $(Build.SourcesDirectory) contents: ?(binclash.log|init-tools.log) logs/**/* targetFolder: $(Build.ArtifactStagingDirectory)

The folders tree for the source looks like: <repo root> `-- binclash.log `-- init-tools.log `-- logs |-- debug `-- release `-- src `-- ml.cs

As listed, this reports finding zero files. However, if I remove logs/**/* then it successfully finds and copies binclash.log and init-tools.log. Is there some syntax related to quotes or line breaks that I am missing?

1 Answers

I had a very similar issue, where I wanted to use a specific folder as my build artifact.

When you target the folder directly: logs/**/*, it returns 0 results.

Instead try using **/logs/**

I have updated your snippet below:

- task: CopyFiles@2
  inputs:
    sourceFolder: $(Build.SourcesDirectory)
    contents:
      ?(binclash.log|init-tools.log)
      **/logs/**
    targetFolder: $(Build.ArtifactStagingDirectory)

When I looked at your code, I noticed that you could simplify to:

- task: CopyFiles@2
  inputs:
    contents: '**/logs/**/?(binclash.log|init-tools.log)'
    TargetFolder: '$(Build.ArtifactStagingDirectory)'
Related