AZ-400 Question 138
Single answerYou manage a monorepo in Azure DevOps containing multiple microservices. You need a YAML pipeline for Microservice A that only runs when changes are committed to the 'ServiceA/' folder on the 'main' branch. Which YAML configuration correctly implements this requirement?
- A
trigger: branches: include: - main paths: include: - 'ServiceA/*'
- B
trigger: branches: exclude: - main paths: exclude: - 'ServiceA/*'
- C
trigger: branches: include: - main paths: include: - 'ServiceA' exclude: - 'Database/*'
- D
stages:
- stage: Build condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')
Show answer and explanation
Correct answer: A
Explanation
In Azure DevOps YAML pipelines, you can control continuous integration triggers using 'branches' to include or exclude specific branches and 'paths' to include or exclude folders. The correct snippet uses 'include' on the 'main' branch and aims the path filter at 'ServiceA/*'. Reference: https://learn.microsoft.com/azure/devops/pipelines/repos/github?view=azure-devops#yaml-triggers (similar concepts apply for Azure Repos), which covers specifying branch and path triggers in YAML.
- A. Correct.
Correct. This configuration ensures that the pipeline is triggered only on the 'main' branch and only when changes occur within the 'ServiceA/' folder. Both 'branches' and 'paths' are explicitly included.
- B. Incorrect.
Incorrect. Excluding the 'main' branch and the 'ServiceA/*' folder would prevent any build from triggering under those conditions. This is the opposite of what is required.
- C. Incorrect.
Incorrect. Although the branch and include path partially match the requirement, specifying 'ServiceA' without the '/' wildcard might not correctly capture all files, and there's no need to exclude 'Database/' for this specific requirement.
- D. Incorrect.
Incorrect. This condition checks whether the build is on the main branch but does not restrict changes to the 'ServiceA' folder. It would trigger for all changes on the main branch.