dman
dman

Reputation: 11064

Azure pipeline trigger regardless of paths includes

I am trying to force azure devops pipeline only to run when files in the /foo/bar directory are modified. However with the below yaml config, this azure pipeline will run for any files modified in the repo.... including ones outside of /foo/bar. Why is this?

trigger:
  branches:
    include:
    - main
  paths:
    include:
    - bar

Upvotes: 1

Views: 788

Answers (2)

Sau001
Sau001

Reputation: 1664

Very late in the day - but sharing what worked for me. Hope this helps.

In my case, my code resides in Github and the pipeline is hosted in Azure Devops.

I was facing the issue of PR getting trigerred even when a commit had a file that was in the exlcusion list, but I eventually found a suitable explanation. Please read the Caveats section below

Project folder hierarchy

I wanted aks/project1/cicd.yaml to respond to changes only when files under aks/project1 get touched.

--c:\work\
    |
    ---aks
    |    |
    |    |
         | ---project1
         |         |
         |         |---cicd.yaml
         |         
         |         
         | ---project2
         |         |
         |         |
         |         |---main.py
         |         |
         |         |---cicd.yaml

trigger and pr elements from my project1/cicd.YAML

trigger: 
  branches:
    include:
    - master
    - main
  paths:
    include:
    - 'aks/project1/*'
    exclude:
    - aks/readme.md


pr:
  paths:
    include: 
    - 'aks/project1/*'
    exclude:
    - aks/readme.md

Caveat about PR path exclusion

The PR path trigger examines all the files in union of all commits. If commit-2 has a file in the exclusion list but there was a prior commit-1 which had a file that was in the inclusion list, the PR will get trigerred . The included file in the commit-1 makes the entire PR trigger to evaluate to True. This was not obvious to me first. But, I found this post which sort of made sense: https://developercommunity.visualstudio.com/t/azure-pipelines-triggers-pathsexclude-in-pr-is-not/1046653

Upvotes: 0

Krzysztof Madej
Krzysztof Madej

Reputation: 40683

Please add exclude as follows:

trigger:
  branches:
    include:
    - main
  paths:
    include:
    - bar
    exclude:
    - '*'

Upvotes: 2

Related Questions