3.4.6 Commit Code to Invoke Build/Test/Deploy

Commit Code to Invoke Build, Test, and Deployment

CodePipeline Flow

Git Push → Source Stage → Build Stage → Test Stage → Deploy Stage

Pipeline Triggers

SourceTrigger
GitHubWebhook via CodeStar Connection
S3CloudTrail event on PutObject
ECRImage push event

CodeBuild — buildspec.yml

version: 0.2
phases:
  install:
    runtime-versions:
      python: 3.12
  pre_build:
    commands:
      - pip install -r requirements.txt
      - pytest tests/
  build:
    commands:
      - sam build
      - sam package --s3-bucket $BUCKET --output-template packaged.yaml
artifacts:
  files:
    - packaged.yaml

Pipeline Concepts

ConceptMô tả
StageLogical group (Source, Build, Deploy)
ActionTask within stage
ArtifactFiles passed between stages (S3)
TransitionCan be disabled between stages

Exam Tip: Git push → webhook → CodePipeline. buildspec.yml phases: install → pre_build → build → post_build. Artifacts stored in S3.