4

I have this structure of projects (folders) in git repository:

/src
/src/Sample.Backend.Common
/src/Sample.Backend.Common.Tests
/src/Sample.Backend.Common.Domain
/src/Sample.Backend.Common.Domain.Tests
/src/Sample.Backend.Pricing.Abstractions
/src/Sample.Backend.Pricing.Domain
/src/Sample.Backend.Pricing.Domain.Tests
/src/Sample.Backend.Pricing.Persistence
/src/Sample.Backend.Pricing.Persistence.Tests
/src/Sample.Backend.Accounting.Abstractions
/src/Sample.Backend.Accounting.Domain
/src/Sample.Backend.Accounting.Domain.Tests
/src/Sample.Backend.Accounting.Persistence
/src/Sample.Backend.Accounting.Persistence.Tests
/src/Sample.Backend.Api
/src/Sample.Common
/src/Sample.Frontend.Common
/src/Sample.Frontend.Web
/src/Sample.Tests.Common

(The sample is simplified, in real there are much more projects/folders.)

I want different pipelines for different parts. For example a pipeline to be triggered whenever any file is commited in master branch in any Backend project. Something like this:

trigger:
  branches:
    include:
    - master
  paths:
    include:
    - src/Sample.Backend.*
    - src/Sample.Common
    - src/Sample.Tests.Common

The problem is, that filter src/Sample.Backend.* is not working. I have to add exact name of each Backend folder to get it working. I could use exclude but I have the same problem - there are many other projects and I would have to name them all.

I found that wildcards are not supported: https://github.com/MicrosoftDocs/azure-devops-docs/issues/397#issuecomment-422958966

Is there any other way to achieve the same result?

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
Lubos
  • 125
  • 2
  • 10
  • How about the issue? Does the answer below resolved your question, If not, would you please let me know the latest information about this issue? – Leo Liu Sep 23 '20 at 07:27

4 Answers4

5

Does Azure YAML pipelne support wildcards in path filter in trigger?

This is a known request on our main forum for product:

Support wildcards (*) in Trigger > Path Filters

This feature has not yet been implemented; you could add your comment and vote this on user voice.

As a workaround for us, we add an inline PowerShell task as the first task to execute the git command line git diff HEAD HEAD~ --name-only then get the modified file names and filter the files name in the latest submit, and use Logging Command to sets variables which are then referenced in custom conditions in the next steps in the build pipeline:

and(succeeded(), eq(variables['CustomVar'], 'True'))

Our inline PowerShell script:

cd $(System.DefaultWorkingDirectory)

$editedFiles = git diff HEAD HEAD~ --name-only

echo "$($editedFiles.Length) files modified:"

$editedFiles | ForEach-Object {
   echo $_
    Switch -Wildcard ($_ ) {
        'XXXX/Src/Sample.Backend.*' { 
              Write-Host ("##vso[task.setvariable variable=CustomVar]True")
         }        
        'XXXX/Src/Sample.Common*' { 
              Write-Host ("##vso[task.setvariable variable=CustomVar]True")}
        'XXXX/Src/Sample.Tests.Common' { 
              Write-Host ("##vso[task.setvariable variable=CustomVar]True")}

    }
}

Then add the condition for all remaining tasks:

enter image description here

In this case, if the changed files do not meet our filters, then all remaining tasks will be skipped.

bubbleking
  • 3,329
  • 3
  • 29
  • 49
Leo Liu
  • 71,098
  • 10
  • 114
  • 135
4

UPDATE: 09/09/2021

This is possible now as it is written here

Wild cards can be used when specifying inclusion and exclusion branches for CI or PR triggers in a pipeline YAML file. However, they cannot be used when specifying path filters. For instance, you cannot include all paths that match src/app//myapp*. This has been pointed out as an inconvenience by several customers. This update fills this gap. Now, you can use wild card characters (, *, or ?) when specifying path filters.

Note: documentation seems to be not updated yet.

Old answer:

No this is not possible at the moment. You have even feature request here and I would recommend to upvote it. (I already did this) Rick in above mentioned topic shared his idea how to overcome the issue:

I currently achieve this by having 3 files:

It works well enough, but it is unfortunate for the need to go through these loops.

But it needs an extra work.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
1

This feature will roll out over the next two to three weeks according to the latest release notes

Pavlo
  • 31
  • 5
  • Have you had any luck with it? Its been 4 weeks now and its still not working for us. – 5NRF Oct 06 '21 at 09:28
  • There is an update in developercommunity thread https://developercommunity.visualstudio.com/t/support-wildcards-in-trigger-path-filters-1/366363#T-N1546999 – Pavlo Oct 07 '21 at 10:07
1

Update on this.

It took a few weeks but the change mentioned by pavlo in the comments above finally got rolled out and path triggers are now supported in YAML.

5NRF
  • 401
  • 3
  • 12