Prepare and test your skills

Prepare and test your skills

Free sample question with answers and detailed explanation below. The Professional Cloud Developer practice bank has an additional 608 practice questions.Try 10 free realistic questions: instant score, no credit card, and no account required.
A development team is building a CI/CD pipeline on Google Cloud for a Go microservice stored in a Git repository. They want to automate a multi-step build process across dev, staging, and prod environments while maintaining a single build configuration file.
The pipeline must satisfy the following requirements:
dev, staging, or main branches.How should the team configure Cloud Build to meet these requirements?
steps in cloudbuild.yaml to run the Go unit tests and build the Docker image using custom variables named $REGION and $AR_REPO alongside $SHORT_SHA, and set substitutionOption: ALLOW_LOOSE so Cloud Build accepts the custom variable names. Create a single Cloud Build trigger watching all branches and pass the environment-specific repository values using --substitutions.ALLOW_LOOSE doIn Cloud Build, user-defined substitutions allow you to parameterize cloudbuild.yaml values at build time, while substitutionOption: ALLOW_LOOSE controls whether Cloud Build raises an error when a declared substitution key is missing or unused. However, Cloud Build enforces strict naming rules on user-defined variables.
_) and contain only uppercase letters, numbers, and underscores (_[A-Z0-9_]+). Variables named $REGION and $AR_REPO lack the leading underscore, so Cloud Build rejects them rather than treating them as valid custom substitutions.ALLOW_LOOSE: Setting substitutionOption: ALLOW_LOOSE only prevents build failures caused by unmatched or missing substitution keys; it does not relax the underscore naming convention, and it is already enabled by default on trigger-invoked builds.$_VARIABLE_NAME to prevent naming collisions with Cloud Build's built-in variables like $PROJECT_ID and $LOCATION.ALLOW_LOOSE, manual builds fail if a substitution is defined in substitutions: but unused in steps: or vice versa.^dev$, ^staging$, ^main$) to distinct environment parameters.This configuration would work only if the custom variables were properly prefixed with underscores (such as $_REGION and $_AR_REPO) and separate triggers were configured for each branch's environment values.
Dockerfile instead of a cloudbuild.yaml file, and override the built-in $PROJECT_ID and $BUILD_ID substitution variables in each trigger to separate dev, staging, and prod Artifact Registry targets and image tags.Dockerfile-only triggers and built-in substitutions doCloud Build triggers can build a container image directly from a Dockerfile without requiring a cloudbuild.yaml file for simple single-image builds. Built-in substitutions such as $PROJECT_ID and $BUILD_ID are system-provided metadata variables automatically injected by Cloud Build at runtime.
$PROJECT_ID or $BUILD_ID: Cloud Build explicitly prohibits overriding $PROJECT_ID and $BUILD_ID in substitution settings, unlike other default substitutions (such as $TAG_NAME or $BRANCH_NAME) or user-defined _ variables.Dockerfile bypasses cloudbuild.yaml, removing the ability to define distinct Cloud Build steps for running Go unit tests, outputting test reports, or orchestrating conditional post-build actions.$BUILD_ID could be overridden, it represents a unique build UUID rather than the Git commit's $SHORT_SHA requested by the team.$PROJECT_ID and $BUILD_ID are strictly read-only and tied to the active Google Cloud project and build execution.Dockerfile builds: A Dockerfile without a build config file is intended for straightforward docker build operations, not multi-step CI/CD pipelines with separate test runners or Artifact Registry publishing logic.cloudbuild.yaml from the final runtime Dockerfile also helps keep production container images smaller and cleaner.Using a Dockerfile directly in a trigger would be suitable only if the team needed a simple, single-step container build with no separate unit-test orchestration, no custom multi-environment substitutions, and standard image naming.
steps in cloudbuild.yaml to run the Go unit tests, execute docker build using $PROJECT_ID, $SHORT_SHA, and user-defined substitutions such as $_REGION and $_AR_REPO, and push the image to Artifact Registry. Create separate Cloud Build triggers for each branch that reference the same cloudbuild.yaml file and supply environment-specific values for the user-defined substitutions.cloudbuild.yaml with branch triggers isA Cloud Build configuration file (cloudbuild.yaml) defines an ordered sequence of containerized build steps executed by Cloud Build. By combining built-in substitutions (such as $PROJECT_ID and $SHORT_SHA) with user-defined substitutions (prefixed with an underscore, like $_REGION and $_AR_REPO), a single pipeline definition can dynamically target different Artifact Registry repositories when invoked by Cloud Build triggers.
steps field serially. Placing the golang test step before the gcr.io/cloud-builders/docker build step ensures the pipeline stops immediately if any unit test returns a non-zero exit code.$SHORT_SHA (the first seven characters of $COMMIT_SHA) for trigger-based builds, allowing docker build to tag images as ${_REGION}-docker.pkg.dev/$PROJECT_ID/${_AR_REPO}/myimage:$SHORT_SHA.$_AR_REPO (and $_REGION if needed) so the docker push step or images field publishes the container to the dev, staging, or prod Artifact Registry repository.^dev$, ^staging$, and ^main$ lets the team reuse a single cloudbuild.yaml across all environments.$PROJECT_ID, $SHORT_SHA, $BRANCH_NAME, and $COMMIT_SHA at build time.docker cloud builder or the images field.Unlike maintaining duplicate build files or bypassing cloudbuild.yaml with a standalone Dockerfile, parameterizing a single cloudbuild.yaml with user-defined substitutions and per-branch triggers follows standard Cloud Build design patterns for multi-environment CI/CD.
steps in cloudbuild.yaml with waitFor: ['-'] on both the test and docker build steps to execute them in parallel, and use a script block with dynamicSubstitutions: true so Cloud Build automatically maps $SHORT_SHA and $_AR_REPO as shell environment variables. Create a Cloud Build trigger for each branch pointing to cloudbuild.yaml.waitFor: ['-'], script, and dynamicSubstitutions doIn Cloud Build, the waitFor field overrides default serial execution so steps can run concurrently, where ['-'] instructs a step to start immediately at the beginning of the build. The script field executes inline shell commands, and dynamicSubstitutions enables bash parameter expansions and nested variable references within substitution definitions.
waitFor: ['-'] on the docker build step causes containerization to run in parallel with the unit tests instead of waiting for them to pass. Even if the unit tests fail, the Docker build will already have started.dynamicSubstitutions: Inside a script block, Cloud Build does not directly substitute variables like $SHORT_SHA or $_AR_REPO. Enabling dynamicSubstitutions: true does not expose substitutions as shell environment variables (and is already true by default on triggers); instead, you must set automapSubstitutions: true or explicitly pass them in the step's env field.waitFor: ['-'] only for independent tasks (such as downloading assets while compiling code) that do not depend on prior steps.script blocks rely on environment variables, requiring automapSubstitutions: true (at the build or step level) or manual env mappings.script, it cannot also specify args or entrypoint.Running steps with waitFor: ['-'] would be appropriate if the two tasks were completely independent (for example, fetching static files from Cloud Storage while running tests), and automapSubstitutions: true were used instead of dynamicSubstitutions: true to expose variables to a script block.
Answer them yourself and get your score the moment you finish. No account needed.
Full access includes
Keep the momentum going with these hand-picked practice scenarios
Last updated Validated