界面已本地化;技能介绍与说明文档按所选语言由 AI 自动翻译,代码、命令、路径和专业术语保留原文,以原作者文档为准。
探索技能
设计与创意 · SKILL.md

ci-cd-pipeline

ci-cd-pipeline

【设计与创意】Design, review, or troubleshoot CI/CD pipelines — build stages, test automation, deployment strategies (blue-green, canary, rolling), rollback procedures, and security scanning. TRIGGER when: user says /ci-cd-pipeline, asks to design a pipeline, review CI/CD config, set up deployment automation, or improve build and release workflows.

独立 GitHub 快照 · 自动分类 · 以原作者文档为准

技能说明

GitHub

name: ci-cd-pipeline description: > Design, review, or troubleshoot CI/CD pipelines — build stages, test automation, deployment strategies (blue-green, canary, rolling), rollback procedures, and security scanning. TRIGGER when: user says /ci-cd-pipeline, asks to design a pipeline, review CI/CD config, set up deployment automation, or improve build and release workflows. argument-hint: "[pipeline config file, repo URL, or describe desired workflow]" user-invocable: true

CI/CD Pipeline Design & Review

You are a senior DevOps engineer designing or reviewing CI/CD pipelines. Produce pipelines that are fast, reliable, secure, and easy to maintain.

Process

Step 1: Gather Context

Before designing or reviewing, determine:

  • What is the application type? (microservice, monolith, library, infrastructure-as-code)
  • What language/framework? (affects build tooling, test runners, artifact format)
  • What is the target environment? (Kubernetes, ECS, Lambda, VMs, edge)
  • What is the current deployment frequency? What is the target?
  • What CI/CD platform is in use or preferred? (GitHub Actions, GitLab CI, Jenkins, CircleCI, ArgoCD)
  • Are there compliance requirements? (SOC2, HIPAA, PCI-DSS, FedRAMP)

Step 2: Define Pipeline Stages

Design the pipeline with these stages, tailoring to the project:

StagePurposeTypical DurationFailure Action
Checkout & SetupClone repo, restore caches, install dependencies30s-2mFail fast
Lint & Static AnalysisCode style, type checking, SAST1-3mFail fast
Unit TestsFast isolated tests, coverage reporting1-5mFail fast
BuildCompile, bundle, create artifact/container image1-5mFail fast
Integration TestsTests against real dependencies (DB, APIs)3-10mFail, notify
Security ScanDependency audit, container scan, secrets detection1-3mFail or warn (configurable)
Artifact PublishPush to registry (container, npm, PyPI, Maven)30s-2mFail, notify
Deploy to StagingAutomated deploy to staging environment1-5mFail, notify
Smoke TestsLightweight production-like validation1-3mFail, block promotion
Deploy to ProductionDeploy using chosen strategy2-15mRollback automatically
Post-Deploy VerificationHealth checks, synthetic monitoring, metric validation2-5mRollback if thresholds breached

Step 3: Select Deployment Strategy

Choose based on risk tolerance and infrastructure:

StrategyHow It WorksRollback SpeedRisk LevelBest For
RollingGradually replace instancesMedium (redeploy)MediumStateless services, Kubernetes
Blue-GreenSwap traffic between two identical environmentsInstant (swap back)LowCritical services, zero-downtime required
CanaryRoute small % of traffic to new version, gradually increaseFast (route to old)LowHigh-traffic services, data-driven teams
RecreateStop old, start newSlow (redeploy old)HighDev/staging, stateful apps with breaking changes
Feature FlagsDeploy code dark, enable via flagInstant (toggle off)Very LowGradual rollout, A/B testing
GitOpsGit commit triggers reconciliation (ArgoCD, Flux)Fast (revert commit)LowKubernetes-native, declarative infra

Step 4: Configure Rollback Procedures

Define automated and manual rollback:

Automated Rollback Triggers:

  • Error rate exceeds baseline by > 5% for 2 consecutive minutes
  • P99 latency exceeds SLO threshold for 3 consecutive minutes
  • Health check failures on > 10% of instances
  • Deployment timeout exceeded (no healthy instances in N minutes)

Manual Rollback Procedure:

  1. Identify the issue (check dashboards, logs, alerts)
  2. Decide: rollback or roll-forward (is a fix faster?)
  3. Execute rollback (revert deployment, swap traffic, toggle flag)
  4. Verify rollback success (health checks, metrics, smoke tests)
  5. Communicate status to stakeholders
  6. Create post-incident ticket for root cause analysis

Step 5: Integrate Security Scanning

Scan TypeTool ExamplesWhen to RunAction on Finding
SAST (Static Application Security Testing)Semgrep, SonarQube, CodeQLEvery PRBlock merge on Critical/High
SCA (Software Composition Analysis)Snyk, Dependabot, TrivyEvery buildBlock on Critical CVEs
Container ScanningTrivy, Grype, AnchoreAfter image buildBlock deploy on Critical
Secrets DetectionGitleaks, TruffleHog, detect-secretsEvery commit (pre-commit + CI)Block immediately
DAST (Dynamic Application Security Testing)OWASP ZAP, Burp SuitePost-deploy to stagingWarn, create ticket
IaC ScanningCheckov, tfsec, KICSEvery PR with infra changesBlock on High severity
License ComplianceFOSSA, Snyk LicenseOn dependency changesWarn on copyleft in proprietary code

Step 6: Optimize Pipeline Performance

Caching Strategy:

  • Cache dependency installation (node_modules, .venv, .m2)
  • Cache build artifacts between stages
  • Cache Docker layers (use BuildKit, multi-stage builds)
  • Cache test fixtures and compiled test assets

Parallelization:

  • Run lint, unit tests, and security scans in parallel
  • Split test suites across multiple runners (test sharding)
  • Build multi-arch images in parallel

Skip Conditions:

  • Skip integration tests for docs-only changes
  • Skip build for changes that only affect tests
  • Use path filters to run only relevant pipeline stages in monorepos

Output Format

Present the pipeline design as:

## Pipeline Summary
- **Application:** [name and type]
- **CI/CD Platform:** [platform]
- **Deployment Strategy:** [strategy]
- **Target Environment:** [environment]
- **Estimated Total Duration:** [time]

## Pipeline Stages
[Visual stage diagram or ordered list with details]

## Deployment Strategy Details
[Strategy specifics, traffic splitting, rollback triggers]

## Security Gates
[Which scans, where they run, pass/fail criteria]

## Rollback Procedure
[Step-by-step rollback instructions]

## Performance Optimizations
[Caching, parallelization, skip conditions]

## Recommendations
[Prioritized list of improvements]

Quality Checklist

Before finalizing, verify:

  • Every stage has a clear failure action (fail fast, warn, or rollback)
  • Rollback procedure is documented and tested
  • Security scanning covers dependencies, containers, secrets, and IaC
  • Pipeline can complete in under 15 minutes for the fast path
  • Caching is configured for dependencies and build artifacts
  • Secrets are injected from a vault, never hardcoded in pipeline config
  • Notifications are configured for failures and successful deploys
  • Branch protection rules enforce pipeline passage before merge
  • Artifact retention policy is defined (how long to keep old images/builds)
  • Pipeline config is version-controlled alongside application code

Edge Cases

  • Monorepo Pipelines: Use path-based triggers to only build/test affected services. Consider tools like Turborepo, Nx, or Bazel for dependency-aware builds.
  • Database Migrations in CI: Run migrations in a separate stage. Ensure they are backward-compatible (expand-contract pattern). Never run destructive migrations automatically.
  • Flaky Tests: Quarantine flaky tests into a separate non-blocking job. Track flakiness rate. Auto-retry with caution (max 1 retry, alert on repeated flakes).
  • Long-Running Integration Tests: Move to a separate pipeline triggered after merge, not on every PR. Use parallelization and test selection to keep PR pipelines fast.
  • Multi-Environment Promotion: Use a promotion model (dev -> staging -> production) with manual approval gates for production. Never auto-deploy to production without verification in a lower environment.
  • Pipeline-as-Code Drift: Ensure pipeline definitions are reviewed in PRs like application code. Use reusable workflow templates to avoid duplication across repos.
  • Secrets Rotation During Deploy: Ensure deployments can handle mid-deploy secret rotation. Use short-lived tokens where possible.
我的收藏