Question 247 of 500
Building and testing applicationsmediumMultiple ChoiceObjective-mapped

Quick Answer

The correct approach is to use a single Cloud Build trigger with a substitution variable for the branch name, and include a conditional step that runs deployment only when the variable equals 'main'. This works because Cloud Build automatically injects the triggering branch into the predefined substitution variable `$_BRANCH`, allowing you to write a simple `if` condition in your `cloudbuild.yaml` that gates the deploy step while still running the build step for all branches. On the Google Professional Cloud Developer exam, this scenario tests your understanding of Cloud Build triggers and substitution variables as a way to avoid duplicating triggers or using external filtering services. A common trap is to create separate triggers for each branch, which violates the principle of single-source configuration and adds maintenance overhead. Remember the memory tip: “One trigger, one build, conditional deploy—let `$_BRANCH` be the gatekeeper.”

PCD Building and testing applications Practice Question

This PCD practice question tests your understanding of building and testing applications. This is a configuration task: choose the command set that satisfies every stated requirement. Small differences — like 'secret' vs 'password' or 'transport input ssh' vs 'all' — change whether the answer is correct. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

A team uses Cloud Build to build a Go application and deploy it to Cloud Run. The build triggers from a GitHub repository. The team wants to ensure that only commits to the 'main' branch trigger a production deployment, while other branches trigger a build but not a deployment. How should they configure this?

Question 1mediummultiple choice
Full question →

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

Use a single Cloud Build trigger with a substitution variable for the branch name, and include a conditional step that runs deployment only when the variable equals 'main'.

Option C is correct because Cloud Build supports substitution variables like $_BRANCH, which automatically receive the branch name from the trigger event. By using a conditional step in cloudbuild.yaml that checks if $_BRANCH equals 'main', you can run the deployment step only for main branch commits, while still building on all branches. This approach keeps a single trigger and avoids unnecessary duplication or external filtering.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Answer analysis

Option-by-option breakdown

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

  • Configure the GitHub repository to only send push events from the main branch to Cloud Build.

    Why it's wrong here

    Cloud Build receives events from GitHub; branch filtering is done at trigger level.

  • Use a conditional step in cloudbuild.yaml that checks the $_BRANCH variable and skips deployment if not main.

    Why it's wrong here

    $_BRANCH is not a predefined variable; $BRANCH_NAME is.

  • Use a single Cloud Build trigger with a substitution variable for the branch name, and include a conditional step that runs deployment only when the variable equals 'main'.

    Why this is correct

    Use $BRANCH_NAME and condition in build config.

    Related concept

    Read the scenario before looking for a memorised answer.

  • Create two separate Cloud Build triggers: one for main branch with deployment step, and one for all branches without deployment step.

    Why it's wrong here

    This works but is not the most efficient; also possible with a single trigger.

Common exam traps

Common exam trap: answer the scenario, not the keyword

Cisco often tests the distinction between using a single trigger with conditional logic versus multiple triggers, where candidates may incorrectly assume that multiple triggers are required or that GitHub can filter events at the source, when in fact Cloud Build handles branch filtering through substitution variables and conditional steps.

Detailed technical explanation

How to think about this question

Cloud Build triggers automatically populate built-in substitution variables like $BRANCH_NAME (or $_BRANCH when using custom substitutions) based on the event source. The conditional step can use shell scripting (e.g., in a 'bash' or 'sh' entrypoint) to check the branch and conditionally run the deployment command, such as 'gcloud run deploy'. This pattern is common in CI/CD pipelines to separate build and deploy phases without creating multiple triggers, reducing maintenance overhead and ensuring consistent build behavior across branches.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A cloud solutions architect for a retail company is evaluating services for a new workload. The correct answer here reflects best practice for the specific scenario described — not a general cloud recommendation. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Cloud exam questions reward reading the constraint carefully: the same technology can be right or wrong depending on the use case.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related PCD practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free PCD practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this PCD question test?

Building and testing applications — This question tests Building and testing applications — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: Use a single Cloud Build trigger with a substitution variable for the branch name, and include a conditional step that runs deployment only when the variable equals 'main'. — Option C is correct because Cloud Build supports substitution variables like $_BRANCH, which automatically receive the branch name from the trigger event. By using a conditional step in cloudbuild.yaml that checks if $_BRANCH equals 'main', you can run the deployment step only for main branch commits, while still building on all branches. This approach keeps a single trigger and avoids unnecessary duplication or external filtering.

What should I do if I get this PCD question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

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

Same concept, more angles

2 more ways this is tested on PCD

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. A developer is setting up a Cloud Build configuration file for a Node.js application. They want to ensure that build steps are executed only when changes are pushed to the 'main' branch. What is the correct approach?

easy
  • A.Use a script in the build step to check the branch name
  • B.Use Cloud Scheduler to trigger builds based on time intervals
  • C.Use a condition in the build config file
  • D.Use a build trigger with a branch filter

Why D: Option D is correct because Cloud Build triggers can be configured with a branch filter (e.g., `^main$`) that ensures builds are only initiated when changes are pushed to the specified branch. This is the native, declarative way to control build execution based on Git branch events, without requiring custom scripting or external scheduling.

Variation 2. A team is setting up a CI/CD pipeline using Cloud Build for a Node.js application. They want to ensure that only code from the main branch is deployed to production. Which TWO practices should they implement?

medium
  • A.Store secrets in Cloud Build and use them in build steps.
  • B.Use Cloud Build substitutions to inject environment variables.
  • C.Use branch triggers to run tests only on push to main.
  • D.Use Cloud Build's inverted match with branch pattern to exclude non-main branches.
  • E.Use a manual approval step in Cloud Deploy before promoting to production.

Why C: Using a branch trigger that runs only on push to main ensures that only main branch code triggers the pipeline. Adding a manual approval step in Cloud Deploy before promoting to production adds a gate to prevent automatic deployment of untested code. Storing secrets or using substitutions are good practices but do not specifically restrict deployment to the main branch.

Keep practising

More PCD practice questions

Last reviewed: Jun 25, 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 PCD practice question is part of Courseiva's free Google Cloud 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 PCD exam.