AZ-400 Question 136
Select 2You are developing a web application and have created a YAML pipeline in Azure DevOps. You want the pipeline to automatically run only when changes are committed to the main branch that affect files in the 'src' folder, and you do not want the pipeline to trigger when changes are made exclusively in the 'docs' folder. Which two actions should you take in your azure-pipelines.yml file to meet these requirements?
- A
In the 'trigger:' section, include only the 'main' branch under branches.
- B
Apply path filters that include 'src/' and exclude 'docs/'.
- C
Disable continuous integration triggers for the main branch in the pipeline settings.
- D
Enable pull request triggers for both 'main' and 'docs' branches to restrict the pipeline runs.
Show answer and explanation
Correct answers: A, B
Explanation
To achieve selective triggering, you must specify which branch(es) will trigger the pipeline and use path filters to include or exclude specific folders. In a YAML pipeline, you would do this by defining 'trigger: branches: include: - main paths: include: - src/* exclude: - docs/*'. This configuration ensures that your pipeline runs only when changes occur in the 'src' folder on the main branch. For more details, see the official Azure DevOps documentation on pipeline triggers and path filters: https://docs.microsoft.com/azure/devops/pipelines/build/triggers
- A. Correct.
Option 1 is correct. By specifying 'main' under the 'trigger:' section (e.g., trigger: branches: include: - main) you ensure that the pipeline only runs for the main branch.
- B. Correct.
Option 2 is correct. Adding path filters to include 'src/' and exclude 'docs/' ensures the pipeline triggers exclusively on changes to the 'src' folder, ignoring commits that only alter the 'docs' folder.
- C. Incorrect.
Option 3 is incorrect. Disabling continuous integration triggers for the main branch would prevent the pipeline from running on main altogether, which is contrary to the goal of triggering on 'src' changes in the main branch.
- D. Incorrect.
Option 4 is incorrect. Enabling pull request triggers for both branches does not ensure that only changes in 'src' on the main branch trigger the pipeline. Instead, it would expand triggers to both 'main' and 'docs' branches.