0
0
GCPcloud~20 mins

Cloud Build for CI/CD in GCP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cloud Build Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Cloud Build trigger creation output
What is the output when you run this command to create a Cloud Build trigger for a GitHub repo?
GCP
gcloud beta builds triggers create github --repo-name=my-repo --repo-owner=my-user --branch-pattern=main --build-config=cloudbuild.yaml
ACreated trigger [my-repo-trigger] for repository [my-user/my-repo] on branch [main].
BERROR: (gcloud.beta.builds.triggers.create.github) argument --repo-name: Must be specified.
CTrigger creation failed: branch pattern 'main' is invalid.
DPermission denied: User does not have roles/cloudbuild.builds.editor.
Attempts:
2 left
💡 Hint
Check the command syntax and required flags for creating a GitHub trigger.
Configuration
intermediate
2:00remaining
Cloud Build YAML step syntax
Which Cloud Build YAML snippet correctly defines a build step that runs a Docker build command?
A
steps:
- executor: 'gcr.io/cloud-builders/docker'
  params: ['build', '-t', 'gcr.io/my-project/my-image', '.']
B
]'.' ,'egami-ym/tcejorp-ym/oi.rcg' ,'t-' ,'dliub'[ :sgra  
'rekcod/sredliub-duolc/oi.rcg' :eman -
:spets
C
steps:
- container: 'gcr.io/cloud-builders/docker'
  run: ['build', '-t', 'gcr.io/my-project/my-image', '.']
D
steps:
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '-t', 'gcr.io/my-project/my-image', '.']
Attempts:
2 left
💡 Hint
Look for the correct keys for specifying the container and arguments in Cloud Build steps.
🔀 Workflow
advanced
2:00remaining
Cloud Build multi-step workflow behavior
Given this Cloud Build YAML with two steps, what happens if the first step fails?
GCP
steps:
- name: 'gcr.io/cloud-builders/gcloud'
  args: ['app', 'deploy']
- name: 'gcr.io/cloud-builders/kubectl'
  args: ['apply', '-f', 'deployment.yaml']
AThe build retries the first step twice before running the second step.
BBoth steps run regardless of the first step's success or failure.
CThe build stops immediately after the first step fails; the second step does not run.
DThe second step runs only if the first step succeeds, but the build does not stop on failure.
Attempts:
2 left
💡 Hint
Consider the default behavior of Cloud Build when a step fails.
Troubleshoot
advanced
2:00remaining
Diagnosing Cloud Build permission errors
You get this error when running a Cloud Build: "Permission denied: User does not have roles/cloudbuild.builds.editor." What is the most likely cause?
AThe Dockerfile has syntax errors causing build failure.
BThe user lacks the required IAM role to execute builds.
CThe build config file is missing or malformed.
DThe Cloud Build trigger is not linked to the correct GitHub repository.
Attempts:
2 left
💡 Hint
Focus on the permission error message and what controls build execution rights.
Best Practice
expert
3:00remaining
Optimizing Cloud Build caching strategy
Which Cloud Build configuration best enables caching to speed up Docker image builds?
A
steps:
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '--cache-from', 'gcr.io/my-project/my-image:latest', '-t', 'gcr.io/my-project/my-image', '.']
options:
  machineType: 'E2_HIGHCPU_8'
B
steps:
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '-t', 'gcr.io/my-project/my-image', '.']
options:
  logging: 'DEBUG'
C
steps:
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '--no-cache', '-t', 'gcr.io/my-project/my-image', '.']
D
steps:
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '-t', 'gcr.io/my-project/my-image', '.']
substitutions:
  _CACHE: 'true'
Attempts:
2 left
💡 Hint
Look for Docker build options that enable cache reuse.