Answers: <p>Your pipeline runs for pull requests not because of the trigger, but because of a build validation policy you've set for one or more target branches (&quot;whenever I create a PR to this branch, start this pipeline&quot;). It's the build validation, as part of a branch's policies: <a href="https://docs.microsoft.com/en-us/azure/devops/repos/git/branch-policies?view=azure-devops#build-validation" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/devops/repos/git/branch-policies?view=azure-devops#build-validation</a></p>
  <p>You probably didn't specify a path filter in the build validation settings. Here's an example of three different build validations in a single branch policy, all with different path filters:</p>
  <p><a href="https://i.sstatic.net/5twU0.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/5twU0.png" alt="Build validation with path filters" /></a></p>
  <p>In short: The path trigger in your YAML has no effect on how a pipeline is triggered for a PR. The trigger you've specified is one that triggers on commits to the master branch, if the commit includes files in the terraform directory.</p>
  
Answers: CC BY-SA 4.0
Answers: 2021-04-13T10:03:55.237Z
Answers: 2021-04-13T10:03:55.237Z
Answers: Walter Vos
Body: <p>I have a multi-stage pipeline for my terraform code. This is my first pipeline so I am sure I'm missing something but there appears to be some inconsistent behaviour that is rather frustrating.</p>
  <p>The pipeline trigger is defined as follows:</p>
  <pre><code>trigger:
    branches:
      include:
        - master
    paths:
      include:
        - terraform/*
  </code></pre>
  <p>My repo has the following folder structure:</p>
  <pre><code>IaC
   |
   +-- terraform
   |    |
   |    +-- main.tf
   |   
   |    
   +-- azure-pipeline.yml
   +-- readme.md
  </code></pre>
  <p>My two stages are defined as follows (I cut out the job steps, its just tarraform commands):</p>
  <pre><code>stages:
    - stage: plan
      displayName: 'terraform plan'
      condition: eq(variables['Build.Reason'], 'PullRequest')
      ...
    - stage: apply
      displayName: 'terraform apply'
      condition: ne(variables['Build.Reason'], 'PullRequest')
      ...
  </code></pre>
  <p>Whenever I update code in the terraform directory and create a PR, the pipeline works exactly as expected.  It does the terraform plan for the reviewer to see and once the PR is approved, the second stage fires and it does a terraform apply.</p>
  <p>The issue I am having is whenever I update a file outside the terraform directory and create a PR, the first stage still runs! Oddly, once the PR is approved, the second stage does not.</p>
  <p>Are my stage conditions to simple? Does a multi-stage pipeline always have to do something?</p>
  
Comments: CC BY-SA 4.0
Comments: 2020-07-14T06:10:56.397Z
Comments: Not sure if it could be that, but you have mentioned the Path to include files from inside your Terraform directory alone. Did you check by including the outer folder as well? If all files are excluded by default and you explicitly need to include them, then that could be the reason.
Comments: Karthik Venkatesan
Tags: <azure-pipelines>
Title: Multi-Stage Azure Pipeline with a path trigger - first stage always runs
UserDisplayName: Joel
ThreadText: # Multi-Stage Azure Pipeline with a path trigger - first stage always runs
  
  (Asked by: username_0 on 2020-07-13)
  
  I have a multi-stage pipeline for my terraform code. This is my first pipeline so I am sure I'm missing something but there appears to be some inconsistent behaviour that is rather frustrating.
  
  The pipeline trigger is defined as follows:
  
  ```
  trigger:
    branches:
      include:
        - master
    paths:
      include:
        - terraform/*
  
  ```
  
  My repo has the following folder structure:
  
  ```
  IaC
   |
   +-- terraform
   |    |
   |    +-- main.tf
   |   
   |    
   +-- azure-pipeline.yml
   +-- readme.md
  
  ```
  
  My two stages are defined as follows (I cut out the job steps, its just tarraform commands):
  
  ```
  stages:
    - stage: plan
      displayName: 'terraform plan'
      condition: eq(variables['Build.Reason'], 'PullRequest')
      ...
    - stage: apply
      displayName: 'terraform apply'
      condition: ne(variables['Build.Reason'], 'PullRequest')
      ...
  
  ```
  
  Whenever I update code in the terraform directory and create a PR, the pipeline works exactly as expected. It does the terraform plan for the reviewer to see and once the PR is approved, the second stage fires and it does a terraform apply.
  
  The issue I am having is whenever I update a file outside the terraform directory and create a PR, the first stage still runs! Oddly, once the PR is approved, the second stage does not.
  
  Are my stage conditions to simple? Does a multi-stage pipeline always have to do something?
  
  **Tags:** azure-pipelines
  
  > **Comments:**
  > **username_1**: Not sure if it could be that, but you have mentioned the Path to include files from inside your Terraform directory alone. Did you check by including the outer folder as well? If all files are excluded by default and you explicitly need to include them, then that could be the reason.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-04-13. Score: 2
  
  Your pipeline runs for pull requests not because of the trigger, but because of a build validation policy you've set for one or more target branches ("whenever I create a PR to this branch, start this pipeline"). It's the build validation, as part of a branch's policies: <https://docs.microsoft.com/en-us/azure/devops/repos/git/branch-policies?view=azure-devops#build-validation>
  
  You probably didn't specify a path filter in the build validation settings. Here's an example of three different build validations in a single branch policy, all with different path filters:
  
  [![Build validation with path filters](https://i.sstatic.net/5twU0.png)](https://i.sstatic.net/5twU0.png)
  
  In short: The path trigger in your YAML has no effect on how a pipeline is triggered for a PR. The trigger you've specified is one that triggers on commits to the master branch, if the commit includes files in the terraform directory.
  
  
  ---
  
  