Try each one before opening the answer. Every option is explained, with the Google Cloud documentation page that proves it.
Question 1 · choose 1
A build fails in its second step with "No such file: /tmp/version.txt":
steps:
- id: stamp
name: ubuntu
entrypoint: bash
args: ['-c', 'git describe --tags > /tmp/version.txt']
- id: build
name: gcr.io/cloud-builders/docker
entrypoint: bash
args: ['-c', 'docker build --build-arg VERSION=$(cat /tmp/version.txt) -t "$_IMAGE" .']
What should the team change?
AAdd waitFor: ['stamp'] to the build step
BRun both steps with the same builder image, ubuntu, so that they share one container
CSet the step's dir field to /tmp in both steps
DWrite the file to /workspace/version.txt and read it from there
Show the answer and why
AAdd waitFor: ['stamp'] to the build step
Incorrect
The order isn't the problem: a file outside a volume is gone when the first step's container is discarded.
BRun both steps with the same builder image, ubuntu, so that they share one container
Incorrect
Each step runs in its own container that is discarded afterwards, whatever the image.
CSet the step's dir field to /tmp in both steps
Incorrect
Files in /tmp still disappear with the first container.
DWrite the file to /workspace/version.txt and read it from there
Correct
Anything written to /workspace, the default volume, is available to later steps.
Cloud Build runs each build step in an isolated container that is discarded after the step. Volumes keep their contents for the whole build: /workspace is the default volume, into which the source is extracted, and user-defined volumes can be attached to steps. Files written to /tmp in one step are not available to the next.
To speed up a build, an engineer added waitFor: ['-'] to the test step:
steps:
- id: codegen
name: gcr.io/cloud-builders/npm
args: ['run', 'generate'] # writes /workspace/src/api.gen.ts
- id: test
name: gcr.io/cloud-builders/npm
args: ['test']
waitFor: ['-']
- id: lint
name: gcr.io/cloud-builders/npm
args: ['run', 'lint']
waitFor: ['-']
Since then, the test step fails now and then because src/api.gen.ts is
missing or incomplete. Which change fixes it and keeps lint running in
parallel?
ASet waitFor: ['codegen'] on the test step
BMove the test step above the codegen step in the file
CWrite the generated file to a user-defined volume instead of /workspace
DGive the test step its own timeout of 10 minutes
Show the answer and why
ASet waitFor: ['codegen'] on the test step
Correct
The test step then starts only after codegen completes, while lint still starts at once.
BMove the test step above the codegen step in the file
Incorrect
With waitFor: ['-'], the test step starts at the beginning of the build wherever it is listed.
CWrite the generated file to a user-defined volume instead of /workspace
Incorrect
Either location is shared; the test step still starts before codegen has written the file.
DGive the test step its own timeout of 10 minutes
Incorrect
A timeout limits how long the step runs; it doesn't make it wait for codegen.
The waitFor field controls when a step starts. waitFor: ['-'] makes a step run immediately when the build starts, in parallel with others, and waitFor with step IDs makes it wait until those steps have completed. Because /workspace is shared, the test step must wait for the codegen step that writes the file it reads.
A repository has no .gcloudignore file. Its .gitignore lists config/generated.json, a file that a local script creates and that the Dockerfile copies into the image. A developer runs gcloud builds submit from the repository root, and the docker build step fails because config/generated.json isn't found. What should the developer do?
APass the file's path in the --substitutions flag of gcloud builds submit
BRun the build with --no-source so that gcloud uploads the directory as it is
CAdd a .gcloudignore file that excludes what should be skipped but not config/generated.json
DCommit config/generated.json to Git but keep it listed in .gitignore
Show the answer and why
APass the file's path in the --substitutions flag of gcloud builds submit
Incorrect
Substitutions replace variables in the build config; they don't add files to the uploaded source.
BRun the build with --no-source so that gcloud uploads the directory as it is
Incorrect
--no-source is for builds that have no source to pass in, so nothing is uploaded.
CAdd a .gcloudignore file that excludes what should be skipped but not config/generated.json
Correct
Without a .gcloudignore file, gcloud generates one that respects the .gitignore entries, so the file is never uploaded.
DCommit config/generated.json to Git but keep it listed in .gitignore
Incorrect
gcloud builds submit uploads the local directory and still applies the .gitignore-based rules to it.
gcloud builds submit uploads the files in the specified directory. If a .gcloudignore file exists in the top-level directory, the files it lists are ignored; if there is none but a .gitignore exists, the gcloud CLI generates a Git-compatible .gcloudignore that respects the ignored files. A file listed in .gitignore therefore never reaches the build unless an explicit .gcloudignore says otherwise.
On a build server, ~/.docker/config.json contains:
{"credHelpers": {"europe-docker.pkg.dev": "gcloud"},
"auths": {"europe-docker.pkg.dev": {"auth": "b2F1dGgy..."}}}
The gcloud CLI there is signed in as a user without write access. A release
script logs in to europe-docker.pkg.dev with docker login, using an access
token of the release service account, which has Artifact Registry Writer.
The push is still denied. What explains it?
AAccess tokens are refused by Artifact Registry for Docker pushes
BDocker uses the credential helper for that host first, so the token in auths is ignored
CArtifact Registry Writer allows pulls only, so a push needs the Repository Administrator role
Ddocker login stores the token in credStore, which Docker reads last
Show the answer and why
AAccess tokens are refused by Artifact Registry for Docker pushes
Incorrect
A short-lived service account access token is a documented password option for Docker.
BDocker uses the credential helper for that host first, so the token in auths is ignored
Correct
Docker checks for a credential helper for the host first; with both sections present, auths is ignored.
CArtifact Registry Writer allows pulls only, so a push needs the Repository Administrator role
Incorrect
The role isn't the issue: the push is made as the gcloud user, not as the release service account.
Ddocker login stores the token in credStore, which Docker reads last
Incorrect
A token used as a password is stored in the auths section, which is ignored here because of credHelpers.
Docker keeps authentication settings in config.json: credential helper settings in credHelpers, and passwords such as an access token in auths. When Docker connects to a registry, it first checks for a credential helper associated with that host, so if config.json has Artifact Registry settings in both sections, the auths settings are ignored. Here the gcloud helper authenticates as the gcloud CLI's signed-in user.
This build config tags images correctly when a trigger runs it, but a
manual gcloud builds submit run tags the image with the unexpanded text
instead of the repository path:
steps:
- name: gcr.io/cloud-builders/docker
args: ['build', '-t', '${_IMAGE_NAME}', '.']
substitutions:
_LOCATION: europe-west1
_REPOSITORY: apps
_IMAGE_NAME: '${_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${_REPOSITORY}/web'
What should the team add so that manual builds behave like trigger builds?
Aoptions: substitutionOption: 'ALLOW_LOOSE'
B$$ in front of each reference inside _IMAGE_NAME
Coptions: dynamicSubstitutions: true
D--substitutions=_LOCATION=europe-west1,_REPOSITORY=apps on the command
Show the answer and why
Aoptions: substitutionOption: 'ALLOW_LOOSE'
Incorrect
ALLOW_LOOSE only skips the check for missing substitutions; it doesn't expand references inside one.
B$$ in front of each reference inside _IMAGE_NAME
Incorrect
$$ produces a literal $, so the references would never be expanded.
Coptions: dynamicSubstitutions: true
Correct
Triggers always set dynamic substitutions; manual builds need it set in the config for one substitution to reference another.
D--substitutions=_LOCATION=europe-west1,_REPOSITORY=apps on the command
Incorrect
The values are already defined; the reference inside _IMAGE_NAME is what isn't expanded.
A user-defined substitution can reference other variables only when the dynamicSubstitutions option is true. For builds invoked by a trigger, the field is always true; for manual builds, it must be set in the build config file, as the page's example with _IMAGE_NAME referencing ${PROJECT_ID} shows. ALLOW_LOOSE and $$ escaping solve different problems.
A Python service has no Dockerfile. The team wants Cloud Build to build a container image for it straight from source and store it in Artifact Registry. Which command does that?
--pack builds the image with Google Cloud's buildpacks, which need no Dockerfile.
Cgcloud builds submit --no-source
Incorrect
--no-source uploads no source at all, so there is nothing to build.
Dgcloud builds submit --config=cloudbuild.yaml with an empty steps list
Incorrect
A config without steps runs nothing, so no image is built.
Cloud Build can build container images with a Dockerfile or with Google Cloud's buildpacks. To build with buildpacks, run gcloud builds submit --pack with the image name, and optionally a builder such as gcr.io/buildpacks/builder.
A build config lists two images, but its only build step builds one of them:
steps:
- name: gcr.io/cloud-builders/docker
args: ['build', '-t', 'europe-docker.pkg.dev/acme/apps/web', '.']
images:
- europe-docker.pkg.dev/acme/apps/web
- europe-docker.pkg.dev/acme/apps/worker
What happens when the build runs?
ACloud Build pushes web and skips worker with a warning
BCloud Build builds worker from the same Dockerfile and pushes both
CThe build fails, because worker isn't produced
DCloud Build pushes web and creates an empty worker image
Show the answer and why
ACloud Build pushes web and skips worker with a warning
Incorrect
A missing image isn't skipped; it makes the build fail.
BCloud Build builds worker from the same Dockerfile and pushes both
Incorrect
The images field names images to push; it doesn't build anything.
CThe build fails, because worker isn't produced
Correct
If a specified image is not produced during the build, the build fails.
DCloud Build pushes web and creates an empty worker image
Incorrect
Cloud Build doesn't create images that no step built.
The images field lists Docker images that Cloud Build pushes to Artifact Registry. Images that a build creates but doesn't list are discarded at the end of the build, and if a listed image is not produced during the build, the build fails.
A Cloud Build pipeline builds a container image into Artifact Registry and also uploads a command-line binary to a Cloud Storage bucket for download. The team turned on build provenance and expects provenance for both outputs. What will it get?
AProvenance for the container image in Artifact Registry only
BProvenance for both, stored next to each output
CProvenance for the binary only, because images need a signature first
DNo provenance for either output until a private pool is used
Show the answer and why
AProvenance for the container image in Artifact Registry only
Correct
Cloud Build generates build provenance only for artifacts stored in Artifact Registry.
BProvenance for both, stored next to each output
Incorrect
An object in a Cloud Storage bucket isn't stored in Artifact Registry, so it gets none.
CProvenance for the binary only, because images need a signature first
Incorrect
Images in Artifact Registry are exactly what provenance is generated for.
DNo provenance for either output until a private pool is used
Incorrect
The only documented limitation is the Artifact Registry one.
Build provenance is verifiable data about a build. A documented limitation is that Cloud Build only generates build provenance for artifacts stored in Artifact Registry, so a file placed in a Cloud Storage bucket gets none.