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:

      - master
      - terraform/*

My repo has the following folder structure:

 +-- 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):

  - 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?

  • 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. Commented Jul 14, 2020 at 6:10

1 Answer 1


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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.