CopyFiles Task not picking up files
Asked Answered
C

2

7

Using Azure DevOps YAML in a database project build and release pipeline

This bit of code correctly picks up my four dacpac files, I can see these being copied in the console

    - task: CopyFiles@2
      displayName: Copy build output to artifacts staging
      inputs:
        SourceFolder: "$(Build.SourcesDirectory)"
        flattenFolders: true
        Contents: '**\bin\**\*.dacpac'
        TargetFolder: "$(Build.ArtifactStagingDirectory)"

This bit of code correctly picks up my publish files, I can see these being copied in the console

    - task: CopyFiles@2
      displayName: Copy build output to artifacts staging
      inputs:
        SourceFolder: "$(Build.SourcesDirectory)"
        flattenFolders: true
        Contents: '**\PublishProfile\*.publish.xml'
        TargetFolder: "$(Build.ArtifactStagingDirectory)"

This bit of code reports "zero files found"

    - task: CopyFiles@2
      displayName: Copy build output to artifacts staging
      inputs:
        SourceFolder: "$(Build.SourcesDirectory)"
        flattenFolders: true
        Contents: |
          '**\bin\**\*.dacpac'
          '**\PublishProfile\*.publish.xml'
        TargetFolder: "$(Build.ArtifactStagingDirectory)"

This pipe multiline syntax is all over the examples https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/copy-files?view=azure-devops&tabs=yaml#examples

I've also used Get-ChildItem to doubly confirm that the files exist.

It seems like | / multiline doesn't work as described.

Cyanamide answered 27/1, 2022 at 7:28 Comment(0)
C
13

As usual, as I write this I checked in detail and the one difference between my code and the example was single quotes.

So it works if you remove single quotes.

Does anyone even QA this stuff?

    - task: CopyFiles@2
      displayName: Copy build output to artifacts staging
      inputs:
        SourceFolder: "$(Build.SourcesDirectory)"
        flattenFolders: true
        Contents: |
          # NOTE THESE PATHS ARE NOT SURROUNDED BY SINGLE QUOTES
          # EVEN THOUGH THIS WORKS IN THE SINGLE LINE VERSION
          **\bin\**\*.dacpac
          **\PublishProfile\*.publish.xml
        TargetFolder: "$(Build.ArtifactStagingDirectory)"

Other hot tips to save you hours:

  • Use this to list files to help troubleshoot missing files

    - task: Bash@3
      inputs:
        targetType: inline
        workingDirectory: $(PIPELINE.WORKSPACE)
        script: ls -R
    
  • Remember Linux is CASE SENSITIVE - get the case wrong and it won't find your files

  • As of right now, you can't parameterise service connections. Maybe that will change in future

  • It's possible to get indentation wrong in YAML and it gives you no clues

This code makes all the variables in the variable group TST available (these are under "Library" not "Environment" - go figure)

variables:
- group: TST

This code (with extra indentation) doesn't throw an error or give any clues, it just doesn't make any variables available. All your variables like $(MyVariable) will be treated as literals

variables:
  - group: TST
Cyanamide answered 27/1, 2022 at 7:28 Comment(0)
S
0

I ran into this as well and after seeing your post I realized the error - it has nothing to do with the copyfiles task and everything to do with yaml syntax.

The pipeline is considered a "literal" style for scalar values, and nothing is interpreted - all characters and breaks are retained without any parsing (which is why it is often used for multi line values).

see this for more information: https://yaml.org/spec/1.2.2/#literal-style

Stringhalt answered 26/7, 2024 at 19:8 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.