Courseiva
Design and implement build and release pipelineseasyMultiple ChoiceObjective-mapped

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

Your pipeline uses a multi-stage YAML file. You want to conditionally run a stage only when the build is triggered from the 'main' branch. Which expression should you use in the 'condition' property of the stage?

⚠ Common exam trap

Candidates often confuse `Build.SourceBranch` (full ref) with `Build.SourceBranchName` (short name) or assume a simple substring match like `startsWith` is sufficient, leading them to pick options that either compare the wrong variable or use an imprecise matching function.

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

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

The `Build.SourceBranch` variable in Azure Pipelines contains the full Git ref path (e.g., `refs/heads/main`). The `condition` property evaluates expressions at runtime, and using `eq(variables['Build.SourceBranch'], 'refs/heads/main')` precisely matches the full ref for the main branch, ensuring the stage runs only when the trigger originates from that branch.

Answer analysis

Option-by-option breakdown

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

  • startsWith(variables['Build.SourceBranch'], 'main')

    Why it's wrong here

    The startsWith check would incorrectly include any branch whose full ref path begins with 'main', such as 'refs/heads/maintenance', because it only verifies a prefix rather than an exact match. Since Build.SourceBranch contains the full ref string, this condition is too broad for a main-branch-only gate.

  • eq(variables['Build.SourceBranchName'], 'refs/heads/main')

    Why it's wrong here

    Build.SourceBranchName resolves to just the branch name, e.g., 'main', without the 'refs/heads/' prefix. Comparing it to the full ref string 'refs/heads/main' will always evaluate to false, so this condition would never trigger the stage or job.

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

    Why this is correct

    This condition is correct because Build.SourceBranch contains the complete Git ref path, and comparing it directly to the exact string 'refs/heads/main' uniquely identifies the main branch without matching maintenance or other similarly named branches. It is the precise and recommended way to gate on the main branch in Azure Pipelines.

  • eq(variables['Build.SourceBranch'], 'main')

    Why it's wrong here

    Build.SourceBranch always includes the full ref prefix, such as 'refs/heads/main', so comparing it to the bare branch name 'main' will always be false. This condition would never evaluate to true, effectively disabling the pipeline stage or job it guards.

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.