Courseiva
Question 700 of 823
Design and implement build and release pipelineseasyMultiple ChoiceObjective-mapped

AZ-400 Run only on main branch Practice Question

You need to run a set of tasks only when the build pipeline runs for the main branch. Which condition should you add to the job or step?

⚠ Common exam trap

A common mix-up: candidates assume `Build.SourceBranch` contains only the short branch name (like `main`) rather than the full Git ref path (`refs/heads/main`), leading them to choose Option B.

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 `Build.SourceBranch` variable in Azure Pipelines contains the full Git ref (e.g., `refs/heads/main`). Using `eq(variables['Build.SourceBranch'], 'refs/heads/main')` ensures the condition evaluates to true only when the pipeline runs on the main branch. This is the standard way to filter by branch in YAML pipeline 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: eq(variables['Build.SourceBranch'], 'refs/heads/main')

    Why this is correct

    This condition is correct because the Build.SourceBranch variable returns the full ref path, such as 'refs/heads/main', so the equality check accurately triggers only when the build originates from the main branch, ignoring other branches or tags.

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

    Why it's wrong here

    This condition is incorrect because Build.SourceBranch always contains the complete refs/heads/ prefix (e.g., 'refs/heads/main'), so comparing directly to 'main' will never be true, causing the condition to fail and the task to run for no branch.

  • condition: and(succeeded(), eq(variables['System.PullRequest.TargetBranch'], 'main'))

    Why it's wrong here

    This condition is incorrect because System.PullRequest.TargetBranch only has a value during pull request builds and, even then, it checks the target branch rather than the source branch; using it here would not limit the build to only the main branch for regular CI builds, and it also introduces an unnecessary succeeds() check.

  • condition: ne(variables['Build.Reason'], 'PullRequest')

    Why it's wrong here

    This condition is incorrect because it merely excludes pull request builds but still allows the task to run for any branch in a non-PR build (e.g., feature branches, develop), so it does not specifically restrict execution to the main branch as required.

Option-by-option analysis

Why each answer is right or wrong

Understanding why wrong answers are wrong — and when they would be correct — is what separates a 750 score from a 900. The AZ-400 exam frequently reuses these exact scenarios with slightly different constraints.

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

Why this is correct

This condition is correct because the Build.SourceBranch variable returns the full ref path, such as 'refs/heads/main', so the equality check accurately triggers only when the build originates from the main branch, ignoring other branches or tags.

condition: eq(variables['Build.SourceBranch'], 'main')Wrong answer — click to see why

Why this is wrong here

Missing 'refs/heads/' prefix, so it won't match.

condition: and(succeeded(), eq(variables['System.PullRequest.TargetBranch'], 'main'))Wrong answer — click to see why

Why this is wrong here

This checks PR target branch, not the source branch.

condition: ne(variables['Build.Reason'], 'PullRequest')Wrong answer — click to see why

Why this is wrong here

This excludes PRs but does not limit to main branch.

Analysis generated from the official AZ-400blueprint and verified against question context. The “when correct” sections are what AI assistants cite when candidates ask “what’s the difference between these options?”

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 11, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.