Cloud Build is a service in Google Cloud that automates the process of building, testing, and deploying code. It helps teams deliver software faster by automating these steps in a pipeline.
Click to reveal answer
beginner
What file does Cloud Build use to define build steps?
Cloud Build uses a file named cloudbuild.yaml or cloudbuild.json to define the sequence of build steps and actions to perform.
Click to reveal answer
intermediate
How does Cloud Build integrate with source code repositories?
Cloud Build connects with repositories like GitHub or Cloud Source Repositories to automatically trigger builds when code changes are pushed, enabling continuous integration.
Click to reveal answer
intermediate
What is a build trigger in Cloud Build?
A build trigger is a configuration that tells Cloud Build when to start a build automatically, such as on a code push or pull request.
Click to reveal answer
beginner
Name two common build steps you might include in a Cloud Build pipeline.
Common build steps include compiling code, running tests, building Docker images, and deploying to environments.
Click to reveal answer
What file format can you use to define Cloud Build steps?
Acloudbuild.yaml
BDockerfile
Cpackage.json
Dbuild.gradle
✗ Incorrect
Cloud Build uses cloudbuild.yaml or cloudbuild.json files to define build steps.
Which event can trigger a Cloud Build automatically?
ADatabase backup
BManual server restart
CUser login
DCode push to repository
✗ Incorrect
Cloud Build triggers can start builds automatically when code is pushed to a repository.
What is the main purpose of Cloud Build in CI/CD?
AStore source code securely
BMonitor server health
CAutomate building, testing, and deploying code
DManage user permissions
✗ Incorrect
Cloud Build automates the build, test, and deploy steps in a CI/CD pipeline.
Which Google Cloud service is used to store container images built by Cloud Build?
AContainer Registry
BCloud Storage
CBigQuery
DCloud SQL
✗ Incorrect
Container Registry stores Docker images built by Cloud Build.
Can Cloud Build run tests as part of the build process?
ANo, Cloud Build only builds code
BYes, tests can be run as build steps
COnly if tests are written in Python
DOnly after deployment
✗ Incorrect
Cloud Build can run tests as part of the build pipeline to ensure code quality.
Explain how Cloud Build helps automate the software delivery process.
Think about how Cloud Build connects code changes to automatic actions.
You got /4 concepts.
Describe the role of a build trigger in Cloud Build and give an example.
Triggers tell Cloud Build when to start working.
You got /3 concepts.
Practice
(1/5)
1. What is the primary purpose of Google Cloud Build in a CI/CD pipeline?
easy
A. To store large amounts of data
B. To automate building, testing, and deploying code
C. To monitor network traffic
D. To manage user permissions
Solution
Step 1: Understand Cloud Build's role
Cloud Build automates the process of building, testing, and deploying code, which is essential in CI/CD pipelines.
Step 2: Eliminate unrelated options
Storing data, monitoring network traffic, and managing permissions are not primary functions of Cloud Build.
Final Answer:
To automate building, testing, and deploying code -> Option B
Thinking Cloud Build manages network or permissions
Assuming Cloud Build only builds code without testing or deploying
2. Which of the following is the correct way to specify a build step in a Cloud Build YAML file?
easy
A. actions:
- image: 'docker'
run: ['build', '-t', 'image', '.']
B. build_steps:
- container: 'gcr.io/cloud-builders/docker'
commands: ['build', '-t', 'image', '.']
C. steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/my-project/my-image', '.']
D. commands:
- use: 'docker'
execute: ['build', '-t', 'image', '.']
Solution
Step 1: Review Cloud Build YAML syntax
The correct key for build steps is 'steps', and each step uses 'name' for the builder image and 'args' for commands.
Step 2: Compare options to syntax
steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/my-project/my-image', '.'] matches the correct syntax. Other options use incorrect keys like 'build_steps', 'actions', or 'commands'.
The step uses the 'ubuntu' image and runs the command 'echo Hello, Cloud Build!'. This command prints the message to the output.
Step 2: Determine expected output
Since 'echo' prints text, the output will be 'Hello, Cloud Build!'. There is no syntax error or missing image because 'ubuntu' is a valid public image.
Final Answer:
Hello, Cloud Build! -> Option D
Quick Check:
Echo command prints text output [OK]
Hint: Echo commands print their arguments as output [OK]
Common Mistakes:
Assuming build fails due to image name
Thinking no output is produced by echo
Confusing YAML syntax errors with valid syntax
4. You wrote this Cloud Build YAML but the build fails immediately. What is the error?
A. Missing the build context (dot) at the end of args
B. Incorrect builder image name
C. YAML indentation error
D. args should be a string, not a list
Solution
Step 1: Check Docker build command syntax
The Docker build command requires a build context, usually '.' at the end, to specify where to find the Dockerfile.
Step 2: Identify missing argument
The args list misses the '.' context argument, causing the build to fail immediately.
Final Answer:
Missing the build context (dot) at the end of args -> Option A
Quick Check:
Docker build needs context path '.' [OK]
Hint: Always end docker build args with '.' for context [OK]
Common Mistakes:
Assuming image name is wrong
Thinking YAML indentation is the issue
Using string instead of list for args
5. You want to create a Cloud Build pipeline that builds a Docker image, runs tests, and then deploys only if tests pass. Which YAML structure correctly represents this workflow?