GOOGLE-PROFESSIONAL-CLOUD-DEVELOPER practice question 13 of 35

You are using Cloud Build to build a Docker image. You need to modify the build to execute unit and run integration tests. When there is a failure, you want the build history to clearly display the stage at which the build failed. What should you do?

Full set: 265 questions
Answer options
A: Add RUN commands in the Dockerfile to execute unit and integration tests.
B: Create a Cloud Build build config file with a single build step to compile unit and integration tests.
C: Create a Cloud Build build config file that will spawn a separate cloud build pipeline for unit and integration tests.
D: Create a Cloud Build build config file with separate cloud builder steps to compile and execute unit and integration tests. Correct answer
Correct Answer:
D. Create a Cloud Build build config file with separate cloud builder steps to compile and execute unit and integration tests.
Explanation

The most effective way to structure a build process in Cloud Build for clear, stage-specific failure reporting is to use separate build steps. A Cloud Build configuration file (cloudbuild.yaml) defines a build as a series of sequential steps. By creating distinct steps for unit tests and integration tests, each stage is executed and logged independently. If any step fails, the build halts, and the Cloud Build history will explicitly identify the name or ID of the failed step. This directly fulfills the requirement to clearly display the stage at which a failure occurred, which is a fundamental best practice for creating robust CI/CD pipelines.

Why Incorrect

A. Adding RUN commands in the Dockerfile combines all tests into a single docker build step, making it impossible to distinguish a unit test failure from an integration test failure in the Cloud Build logs.
B. A single build step for all tests suffers from the same issue as option A; the build history would only show that one monolithic step failed, without specifying which test suite was the cause.
C. Spawning a separate Cloud Build pipeline is an overly complex and inefficient solution for what can be handled by sequential steps within a single build configuration. It adds unnecessary overhead.

References

1. Google Cloud Documentation, "Build configuration overview": Under the "Build steps" section, the documentation states, "A build config file contains a list of build steps... Cloud Build executes each build step in a container... By default, Cloud Build executes steps of a build serially... If any step in the build fails, the entire build fails." This directly supports using separate, sequential steps (Option D) as the mechanism for isolating stages, where the failure of one step is explicitly reported.

2. Google Cloud Documentation, "Creating CI/CD pipelines": This page provides tutorials and examples of multi-step build configurations. For instance, the "Automating builds for code on GitHub" tutorial shows a cloudbuild.yaml with a distinct test step using npm test and a subsequent build step using docker build. This demonstrates the standard practice of separating testing from building into different steps for clarity and control.

3. Google Cloud Documentation, "Best practices for writing build configs": This guide recommends, "Keep your build steps small. Each build step in your build config file should map to a single logical task." This principle directly advocates for separating unit tests and integration tests into their own steps (Option D) rather than combining them (Option B) or embedding them in a Dockerfile (Option A).

Scroll to Top