Courseiva
Design and implement build and release pipelineseasyMultiple ChoiceObjective-mapped

AZ-400 Practice Question: Design and implement build and release pipelines

Your team is using YAML pipelines in Azure DevOps and wants to ensure that a specific stage runs only for changes to the 'main' branch. Which condition should you add to the stage?

⚠ Common exam trap

Many exam-takers choose option B (`contains`) thinking it is a simpler way to match the branch, but they overlook that `contains` does a substring match and will incorrectly trigger on branches like 'maintenance' or 'main-feature', whereas the exact ref comparison in option D is the precise and safe approach.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')

The `eq(variables['Build.SourceBranch'], 'refs/heads/main')` condition evaluates to true only when the pipeline is triggered by a change to the 'main' branch. In YAML pipelines, conditions are evaluated as expressions, and this simple equality check ensures the stage runs exclusively for that branch. The other options either invert the logic, use a partial match that could include other branches, or unnecessarily combine conditions.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • condition: ne(variables['Build.SourceBranch'], 'refs/heads/main')

    Why it's wrong here

    ne() inverts the equality check, meaning the condition evaluates to true whenever Build.SourceBranch is not exactly 'refs/heads/main'. This causes the stage to run for every other branch – feature branches, release branches, and pull request refs – while skipping the one branch it is supposed to target. The result is the exact opposite of the desired behavior: deployments happen on all branches except main.

  • condition: contains(variables['Build.SourceBranch'], 'main')

    Why it's wrong here

    Using contains() performs a substring match rather than an exact ref comparison. As a result, any branch whose name includes the characters 'main' — such as 'refs/heads/feature/maintenance' or 'refs/heads/main-v2' — would also satisfy the condition and trigger the stage unintentionally. This violates the requirement to run only on the actual main branch and can cause spurious deployments to multiple branches.

  • condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))

    Why it's wrong here

    This condition adds succeeded() before the branch equality check. The succeeded() function evaluates to true only if all previous stages/jobs have completed successfully. The question requires the stage to run whenever the source branch is main, regardless of prior stage results, so this extra check may incorrectly skip a main-branch deployment if an earlier unrelated stage fails. It also unnecessarily couples the branch gate to pipeline health, which is not part of the stated requirement.

  • condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')

    Why this is correct

    This condition uses eq() to perform an exact string comparison against the full source ref 'refs/heads/main'. In Azure Pipelines, Build.SourceBranch contains the full ref, so this matches only the actual main branch and excludes all others, including branches that merely contain 'main' as a substring. It is the precise, minimal condition that satisfies the requirement without adding extra behavior such as succeeded() checks.

About these practice questions

Courseiva writes every AZ-400 question from scratch — 823 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This AZ-400 practice question is part of Courseiva's free Microsoft certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the AZ-400 exam.