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 if the build originates from the 'main' branch. Which syntax should you use?
⚠ Common exam trap
The trap here is that candidates often forget that `Build.SourceBranch` includes the full ref path (`refs/heads/main`) and incorrectly use just the branch name (`main`), or they misuse the `==` operator instead of the `eq()` function required by Azure Pipelines expression syntax.
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 `condition` directive in a YAML pipeline stage evaluates expressions using Azure Pipelines syntax. The `eq()` function compares two values, and `Build.SourceBranch` for the 'main' branch returns `refs/heads/main`, not just `main`. This exact match ensures the stage runs only when the build originates from the 'main' 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.
- ✗
condition: variables['Build.SourceBranch'] == 'main'
Why it's wrong here
This syntax is invalid because a YAML condition must be an expression string using functions like `eq()`, not raw comparison operators. Additionally, `'main'` is not the full ref path; the correct value would be `'refs/heads/main'`.
- ✗
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
Why it's wrong here
This condition is syntactically valid and would work, but it is not the best choice because the default stage condition already requires all previous stages to have succeeded. Explicitly adding `succeeded()` duplicates that implicit behavior, making the YAML harder to read without changing the outcome. For a simple branch check, you should let the default success gate apply and only specify the additional branch condition, which is what the correct answer does.
- ✓
condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')
Why this is correct
This is the correct condition because Azure Pipelines stores the triggering branch in the `Build.SourceBranch` variable as a full ref string, such as `refs/heads/main` or `refs/pull/123/merge` for PR builds. The `eq()` function performs an exact string comparison, so it will correctly match when pipeline runs are triggered by a push to the `main` branch. This is the minimal, readable expression that achieves the intended gating without any redundant conditions.
- ✗
condition: eq(variables['Build.SourceBranch'], 'main')
Why it's wrong here
While the `eq()` function is the correct way to compare values in an Azure Pipelines expression, the value `'main'` does not match the actual format of the `Build.SourceBranch` predefined variable. That variable always returns the fully qualified Git ref, for example `refs/heads/main`, for a branch build. Therefore, the condition will always evaluate to false, and the stage will never run for a push to main. To match the main branch, you must include the `refs/heads/` prefix.
Go deeper
Related to this question
Learn chapter
Introduction to DevOps and Azure DevOps
Key term
Stage
A stage is a discrete phase in a software development or deployment pipeline where code is built, tested, integrated, or released in a controlled environment.
Key term
YAML pipeline
A YAML pipeline is a text-based file written in YAML format that defines an automated series of steps for building, testing, and deploying software in a continuous integration and continuous delivery (CI/CD) system.
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 →
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.