A development team uses AWS CodeCommit for their source code repository and AWS CodePipeline for CI/CD. They want to ensure that every pull request (PR) merge to the `main` branch automatically triggers a build and a suite of unit tests before the code is deployed. How can they configure CodePipeline to achieve this?
- AIntegrate AWS CodeCommit with AWS CodePipeline, configuring the source stage to use the `main` branch as a trigger.
- BSet up an AWS CodeBuild project to poll the `main` branch for changes.
- CUse an AWS Lambda function to monitor CodeCommit PR events and manually trigger CodePipeline.
- DConfigure the CodePipeline to trigger on commits to the `main` branch.
Show answer & explanationAnswer & explanation
Correct answer: A. Integrate AWS CodeCommit with AWS CodePipeline, configuring the source stage to use the `main` branch as a trigger.
AWS CodePipeline natively integrates with AWS CodeCommit. By configuring the CodePipeline source stage to point to the `main` branch of the CodeCommit repository, CodePipeline will automatically detect new commits (including those from merged pull requests) and trigger the pipeline, initiating the build and test stages.
Why the other options are wrong
- B. CodeBuild is for building and testing, not for triggering pipelines based on source code changes. CodePipeline's source stage handles triggering.
- C. Using a Lambda function adds unnecessary complexity as CodePipeline has native integration for this purpose.
- D. While technically correct, option D is more precise as it specifically mentions the integration and the source stage configuration within CodePipeline, which is the direct mechanism.
CodeCommit CodePipeline Integration
The native integration between AWS CodeCommit and AWS CodePipeline that allows CodePipeline to automatically detect changes (e.g., new commits, merged pull requests) in a specified CodeCommit branch and trigger a pipeline execution.
- CodePipeline source stage points to CodeCommit branch.
- Automatically triggers on new commits/merges.
- Enables continuous integration.
Memory trick: TRIGGER-PIPE: Track Repository, Initiate Git, Go Right, Every Push.