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?