Azure-devops-docs: CopyFiles task: Negative globbing doesn't work for me

Created on 14 Nov 2018  Â·  5Comments  Â·  Source: MicrosoftDocs/azure-devops-docs

I'm using a YAML build pipeline definition. I'm trying to exclude the git directory and node_modules directories from my artifact publish. I've tried a bunch of different permutations, but I can't seem to get it to work. Based on the above, and on the note over in the patterns reference doc to use / instead of \ as a path separator (this doc doesn't seem to follow that, however), I'd expect the following config to work. Instead, it copies zero files.

- task: CopyFiles@2
  inputs:
    targetFolder: '$(Build.ArtifactStagingDirectory)'
    contents: |
      '**'
      '!(node_modules|.git)/**'

Alternatively, I'd expect the following to work (this also copies zero files):

- task: CopyFiles@2
  inputs:
    targetFolder: '$(Build.ArtifactStagingDirectory)'
    contents: |
      '**'
      '**/!(node_modules|.git)/**'

This one also doesn't work (again, zero files copied):

- task: CopyFiles@2
  inputs:
    targetFolder: '$(Build.ArtifactStagingDirectory)'
    contents: '**/!(node_modules|.git)/**'

Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri1 devopprod doc-bug

All 5 comments

This definitely needs a brush up!

This didn't work:
!node_modules/**/*

Nor did:
!node_modules/**

Also not working:
!**/node_modules/**

This works:
!$(System.DefaultWorkingDirectory)/node_modules/**

There are a couple separate issues here:

  • You don't need to quote lines in a | string in YAML. So it should be:
contents: |
  **
  **/!(node_modules|.git)/**

That said, it still doesn't seem to work :) so I've filed a bug to get to the bottom of why. https://github.com/microsoft/azure-pipelines-tasks/issues/10395

The parenthetical pattern needs to include a leading +, per fnmatch syntax.

contents: |
  **
  !+(node_modules|.git)/**

We can certainly doc that a little more clearly, so leaving this issue open.

I'm not sure why this issue is closed; I'm using the classic editor, and negative globbing doesn't work for me:

!.git/**/*
!.gitignore

I wondered if it was something with the dot files, but it even fails on something like README.MD.

@mmeneesnh I just set up a task using the classical editor, and I was able to exclude ".git" folder like this:

**/*
!.git/**/*
Was this page helpful?
0 / 5 - 0 ratings

Related issues

csutorasr picture csutorasr  Â·  3Comments

atrauzzi picture atrauzzi  Â·  3Comments

EM1L picture EM1L  Â·  3Comments

dtamai picture dtamai  Â·  3Comments

cijujoseph picture cijujoseph  Â·  3Comments