DevOps Asked on August 22, 2021
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?
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:
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.
Answered by Walter Vos on August 22, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP