How to trigger Cloud Build for code changes?

Your team frequently creates new ML models and runs experiments. Your team pushes code to a single repository hosted on Cloud Source Repositories. You want to create a continuous integration pipeline that automatically retrains the models whenever there is any modification of the code. What should be your first step to set up the CI pipeline?

  1. Configure a Cloud Build trigger with the event set as "Pull Request"
  2. Configure a Cloud Build trigger with the event set as "Push to a branch" Source Reference Answer
  3. Configure a Cloud Function that builds the repository each time there is a code change
  4. Configure a Cloud Function that builds the repository each time a new branch is created

Community Votes

B
100%

100% of anonymous learners picked answer B. Votes are pick records left by other test-takers — they are not the verified answer.

Community Insight

This question tests the selection of the correct Cloud Build trigger event to capture all code changes, where the trap is choosing 'Pull Request' (Option A) which misses direct pushes, or Cloud Functions which are overkill for standard CI.

To automate ML model retraining in Google Cloud, use Cloud Build triggers integrated with Cloud Source Repositories. The community consensus confirms that setting the trigger event to 'Push to a branch' ensures the pipeline runs on every code modification.

Selecting Option A (Pull Request) is a common mistake because, while useful for testing, it does not cover direct pushes to branches, failing the requirement to retrain on 'any modification.'

Community Discussion (6 comments)

forport 👍 1 Selected: B
B. According to Gemini-Advanced.
fitri001 👍 2 Selected: B
Continuous Integration: CI pipelines aim for frequent integration of code changes. Triggering the build pipeline upon every push to a branch (including the main branch) ensures your models retrain whenever the code relevant to them is modified. Focus on Relevant Changes: Compared to option A ("Pull Request"), triggering on pushes allows retraining even for direct pushes to the main branch, not just pull request merges. This can be crucial for catching critical code changes that might bypass pull requests.
pinimichele01 👍 1 Selected: B
For ANY modifications, “Push to a branch” is the best choice in Cloud Build trigger.
guilhermebutzke 👍 1 Selected: B
My Answer B: For ANY modifications, “Push to a branch” is the best choice in Cloud Build trigger. However, when it comes to ML model training, retraining models on every push might be resource-intensive, especially if the training process is computationally expensive. So, I think triggering the CI pipeline on a pull request allows for changes to be tested before merging into the main branch. would be a better choice …
b1a8fae 👍 1 Selected: B
B. Any code change on the Cloud repo is done by pushing to a branch.
pikachu007 👍 4 Selected: B
Cloud Build Integration: Cloud Build is Google Cloud's fully managed CI/CD platform, designed to automate builds and deployments, making it ideal for this task. Trigger on Code Pushes: Setting the trigger event to "Push to a branch" ensures that the pipeline automatically activates whenever new code is pushed to any branch of the repository, aligning with the goal of retraining models on code modifications.

Comments & Corrections

No comments yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

Expert Analysis

Why the Answer Is Correct

Option B is correct because Cloud Build is Google Cloud's native, fully managed CI/CD platform designed to automate builds and deployments. Configuring a trigger on 'Push to a branch' ensures that the pipeline activates whenever new code is committed to any branch, strictly satisfying the requirement to retrain models on 'any modification' of the code.

Why the Other Options Are Wrong

Option A is incorrect because triggering on 'Pull Request' limits automation to only those changes associated with a PR, missing direct commits to the main branch. Options C and D are incorrect because implementing a Cloud Function to handle builds is unnecessarily complex and less efficient than using the native Cloud Build integration, which handles repository events automatically.

Community Comment Notes

Community members emphasize that Cloud Build is the ideal tool for this task due to its seamless integration with Cloud Source Repositories. Several comments highlight that 'Push to a branch' is the superior choice over 'Pull Request' because it captures all code changes, including direct pushes to the main branch. While one comment noted the potential resource intensity of retraining on every push, Option B remains the technically correct answer to meet the specific criteria of the question.

Official Reference

Exam Strategy

When questions ask for actions on 'any modification' or 'every change,' look for 'Push' events rather than 'Pull Request' events to ensure comprehensive coverage. Always prioritize native integrations like Cloud Build triggers over custom solutions like Cloud Functions for standard CI/CD scenarios.

Related Analysis

Practice All PMLE Questions

Access 65 questions with complete answers and detailed explanations.

View Full PMLE Practice Test →

← Back to PMLE Study Guide