AgentSkillsCN

Cicd Patterns

CI/CD 模式

SKILL.md

CI/CD Patterns Skill

Purpose

Best practices for continuous integration and deployment pipelines.

Auto-Invoke Triggers

  • Setting up CI/CD pipelines
  • Configuring automated deployments
  • Implementing quality gates
  • Managing environments

Pipeline Stages

Standard Pipeline

code
Commit → Build → Test → Analyze → Deploy (Staging) → Deploy (Production)

Stage Responsibilities

StagePurposeFailure Action
BuildCompile, dependenciesBlock pipeline
Unit TestFast testsBlock pipeline
Lint/FormatCode qualityBlock pipeline
Integration TestAPI/DB testsBlock pipeline
Security ScanVulnerabilitiesBlock or warn
Deploy StagingTest environmentBlock production
E2E TestUser flowsBlock production
Deploy ProductionLive releaseRollback ready

Branch Strategy

Git Flow

BranchPurposeDeploys To
mainProduction codeProduction
developIntegration branchStaging
feature/*New features-
hotfix/*Emergency fixesProduction
release/*Release prepStaging

Trunk-Based Development

BranchPurposeDeploys To
mainAll codeStaging → Production
feature/*Short-lived branchesPreview

Quality Gates

Build Stage

  • Code compiles without errors
  • Dependencies resolve
  • Build artifacts created

Test Stage

  • Unit tests pass (100%)
  • Coverage threshold met (> 70%)
  • Integration tests pass
  • No test flakiness

Analysis Stage

  • No linting errors
  • No critical security issues
  • No new technical debt

Deploy Stage

  • Health checks pass
  • Smoke tests pass
  • No errors in logs

Environment Strategy

Environment Types

EnvironmentPurposeDataAccess
DevelopmentLocal testingFakeDeveloper
CIAutomated testsTestPipeline
StagingPre-productionSanitizedTeam
ProductionLive usersRealRestricted

Environment Parity

  • Keep environments as similar as possible
  • Use same database type
  • Use same infrastructure (scaled down)
  • Use environment variables for differences

Deployment Strategies

Blue-Green Deployment

  • Two identical environments (Blue/Green)
  • Deploy to inactive environment
  • Switch traffic after verification
  • Easy rollback (switch back)

Canary Deployment

  • Deploy to small percentage of users
  • Monitor errors and metrics
  • Gradually increase traffic
  • Full rollback if issues

Rolling Deployment

  • Update instances one at a time
  • No downtime
  • Mixed versions during deploy
  • Slower rollback

Strategy Selection

StrategyUse When
Blue-GreenZero downtime critical, easy rollback needed
CanaryRisk mitigation, gradual rollout
RollingResource constrained, stateless apps

Secrets Management

Rules

  • Never commit secrets to git
  • Use environment-specific secrets
  • Rotate secrets regularly
  • Audit secret access

Secret Storage

ToolUse Case
GitHub SecretsGitHub Actions
Azure Key VaultAzure pipelines
AWS Secrets ManagerAWS deployments
HashiCorp VaultMulti-cloud

Artifact Management

Versioning

  • Use semantic versioning (MAJOR.MINOR.PATCH)
  • Tag releases in git
  • Include commit SHA in build metadata
  • Version artifacts consistently

Retention

Artifact TypeRetention
Build logs30 days
Test results90 days
Release artifacts1 year
Docker images90 days

Rollback Strategy

Automated Rollback Triggers

  • Health check failures
  • Error rate spike (> 5%)
  • Response time degradation
  • Memory/CPU threshold breach

Rollback Process

  1. Detect failure (automated monitoring)
  2. Trigger rollback (automated or manual)
  3. Deploy previous version
  4. Verify health
  5. Investigate root cause

Rollback Requirements

  • Keep N-1 version deployable
  • Database migrations must be backward compatible
  • Feature flags for risky changes
  • Test rollback procedure regularly

Pipeline Optimization

Speed Improvements

  • Parallelize independent stages
  • Cache dependencies
  • Use incremental builds
  • Skip unchanged components
  • Use faster runners/agents

Target Times

StageTarget
Build< 5 min
Unit tests< 5 min
Integration tests< 10 min
Full pipeline< 30 min

Notifications

When to Notify

EventNotify
Build failureAuthor, Team
Deploy to stagingTeam
Deploy to productionTeam, Stakeholders
RollbackTeam, On-call

Channels

  • Slack/Teams for team notifications
  • Email for stakeholders
  • PagerDuty for critical failures

Best Practices

DO

  • Fail fast (run quick checks first)
  • Use infrastructure as code
  • Version your pipeline configuration
  • Test pipeline changes in feature branches
  • Monitor pipeline metrics
  • Document deployment process

DON'T

  • Skip tests to save time
  • Deploy on Fridays
  • Deploy without monitoring
  • Ignore flaky tests
  • Manual production deploys
  • Store secrets in pipeline config

CI/CD Checklist

Pipeline Setup

  • Build stage configured
  • All test types included
  • Linting and formatting checks
  • Security scanning enabled
  • Deployment stages defined

Quality

  • Quality gates enforced
  • Coverage thresholds set
  • No secret in code
  • Artifacts versioned

Deployment

  • Staging environment exists
  • Rollback procedure tested
  • Health checks configured
  • Notifications set up
  • Monitoring in place