ci-cd-best-practices — Claude Code skill: what it does, how to set up
Provides guidelines for automated pipelines, testing workflows, and zero-downtime deployment patterns. Works with assistants supporting pipeline generation and DevOps tasks.
npx skills add Mindrally/skills --skill ci-cd-best-practices -a claude-codeWhat ci-cd-best-practices does
The skill provides structural blueprints for five pipeline stages: build, test, security, staging, and production. It establishes rules for dependency caching, pinned package versions, and multi-stage Docker builds.
Deployment patterns cover Blue-Green switches, rolling updates via kubectl rollout restart, and Canary rollouts starting at 5% traffic. Testing rules focus on parallel execution, isolated test data, and handling flaky runs with up to 2 retries.
These blueprints assume your external tooling is already configured. Dedicated secret managers like Vault or AWS Secrets Manager and Terraform scripts must exist in your repo beforehand. The skill guides pipeline structure, not pipeline execution.
What it helps with
- configure staged pipelines for build, test, and container scanning
- implement Canary rollouts with traffic percentage gates
- split environment variables securely across staging and production
- set up parallel test execution with shard splitting
Example prompts for the agent
- Draft a pipeline with build, SAST scanning, and staging deployment steps
- Show how to configure a Blue-Green deployment workflow with health checks
- Help me set up sharded parallel test runs in our CI script
How to install ci-cd-best-practices
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill ci-cd-best-practices -a claude-code2Manually: put the files in place
~/.claude/skills/ci-cd-best-practices/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/ci-cd-best-practices/
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill ci-cd-best-practices -a codex2Manually: put the files in place
.agents/skills/ci-cd-best-practices/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill ci-cd-best-practices -a cursor2Manually: put the files in place
.cursor/skills/ci-cd-best-practices/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install Mindrally/skills ci-cd-best-practices2Manually: put the files in place
.github/skills/ci-cd-best-practices/SKILL.md1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill ci-cd-best-practices -a gemini-cli2Platform CLI
gemini skills install https://github.com/Mindrally/skills --path ci-cd-best-practicesManually: put the files in place
.devin/skills/ci-cd-best-practices/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add Mindrally/skills --skill ci-cd-best-practices -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about ci-cd-best-practices
How to install ci-cd-best-practices in Claude Code?
Run npx skills add Mindrally/skills --skill ci-cd-best-practices -a claude-code. This command adds the skill directly to your Claude Code setup.
What does the ci-cd-best-practices skill do?
It instructs the agent on pipeline design, test parallelization, deployment patterns like Blue-Green and Canary, and secret handling.
Which security scan types are covered?
The skill covers SAST, DAST, dependency scanning, container image audits, and secret leak detection.
Source text
SKILL.md · Apache-2.0
---
name: ci-cd-best-practices
description: CI/CD best practices for building automated pipelines, deployment strategies, testing, and DevOps workflows across platforms
metadata:
maintainer: Mindrally
source: https://github.com/Mindrally/skills
---
# CI/CD Best Practices
You are an expert in Continuous Integration and Continuous Deployment, following industry best practices for automated pipelines, testing strategies, deployment patterns, and DevOps workflows.
## Core Principles
- Automate everything that can be automated
- Fail fast with quick feedback loops
- Build once, deploy many times
- Implement infrastructure as code
- Practice continuous improvement
- Maintain security at every stage
## Pipeline Design
### Pipeline Stages
A typical CI/CD pipeline includes these stages:
```
Build -> Test -> Security -> Deploy (Staging) -> Deploy (Production)
```
#### 1. Build Stage
```yaml
build:
stage: build
script:
- npm ci --prefer-offline
- npm run build
artifacts:
paths:
- dist/
expire_in: 1 day
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
```
Best practices:
- Use dependency caching to speed up builds
- Generate build artifacts for downstream stages
- Pin dependency versions for reproducibility
- Use multi-stage Docker builds for smaller images
#### 2. Test Stage
```yaml
test:
stage: test
parallel:
matrix:
- TEST_TYPE: [unit, integration, e2e]
script:
- npm run test:${TEST_TYPE}
coverage: '/Coverage: \d+\.\d+%/'
artifacts:
reports:
junit: test-results.xml
coverage_report:
coverage_format: cobertura
path: coverage/cobertura-coverage.xml
```
Testing layers:
- **Unit tests**: Fast, isolated, run on every commit
- **Integration tests**: Test component interactions
- **End-to-end tests**: Validate user workflows
- **Performance tests**: Check for regressions
#### 3. Security Stage
```yaml
security:
stage: security
parallel:
matrix:
- SCAN_TYPE: [sast, dependency, secrets]
script:
- ./security-scan.sh ${SCAN_TYPE}
allow_failure: false
```
Security scanning types:
- **SAST**: Static Application Security Testing
- **DAST**: Dynamic Application Security Testing
- **Dependency scanning**: Check for vulnerable packages
- **Secret detection**: Find leaked credentials
- **Container scanning**: Analyze Docker images
#### 4. Deploy Stage
```yaml
deploy:staging:
stage: deploy
environment:
name: staging
url: https://staging.example.com
script:
- ./deploy.sh staging
rules:
- if: $CI_COMMIT_BRANCH == "develop"
deploy:production:
stage: deploy
environment:
name: production
url: https://example.com
script:
- ./deploy.sh production
rules:
- if: $CI_COMMIT_BRANCH == "main"
when: manual
```
## Deployment Strategies
### Blue-Green Deployment
Maintain two identical environments:
```yaml
deploy:blue-green:
script:
- ./deploy-to-inactive.sh
- ./run-smoke-tests.sh
- ./switch-traffic.sh
- ./cleanup-old-environment.sh
```
Benefits:
- Zero-downtime deployments
- Easy rollback by switching traffic back
- Full testing in production-like environment
### Canary Deployment
Gradually roll out to subset of users:
```yaml
deploy:canary:
script:
- ./deploy-canary.sh --percentage=5
- ./monitor-metrics.sh --duration=30m
- ./deploy-canary.sh --percentage=25
- ./monitor-metrics.sh --duration=30m
- ./deploy-canary.sh --percentage=100
```
Canary stages:
1. Deploy to 5% of traffic
2. Monitor error rates and latency
3. Gradually increase if metrics are healthy
4. Full rollout or rollback based on data
### Rolling Deployment
Update instances incrementally:
```yaml
deploy:rolling:
script:
- kubectl rollout restart deployment/app
- kubectl rollout status deployment/app --timeout=5m
```
Configuration:
- Set `maxUnavailable` and `maxSurge`
- Health checks determine rollout pace
- Automatic rollback on failure
### Feature Flags
Decouple deployment from release:
```javascript
// Feature flag implementation
if (featureFlags.isEnabled('new-checkout')) {
return <NewCheckout />;
} else {
return <LegacyCheckout />;
}
```
Benefits:
- Deploy disabled features to production
- Gradual feature rollout
- A/B testing capabilities
- Quick feature disable without deployment
## Environment Management
### Environment Hierarchy
```
Development -> Testing -> Staging -> Production
```
Each environment should:
- Mirror production as closely as possible
- Have isolated data and secrets
- Use infrastructure as code
### Environment Variables
```yaml
variables:
# Global variables
APP_NAME: my-app
# Environment-specific
.staging:
variables:
ENV: staging
API_URL: https://api.staging.example.com
.production:
variables:
ENV: production
API_URL: https://api.example.com
```
Best practices:
- Never hardcode secrets
- Use secret management (Vault, AWS Secrets Manager)
- Separate configuration from code
- Document all required variables
### Infrastructure as Code
```hcl
# Terraform example
resource "aws_ecs_service" "app" {
name = var.app_name
cluster = aws_ecs_cluster.main.id
task_definition = aws_ecs_task_definition.app.arn
desired_count = var.environment == "production" ? 3 : 1
deployment_configuration {
maximum_percent = 200
minimum_healthy_percent = 100
}
}
```
## Testing Strategies
### Test Pyramid
```
/\
/ \ E2E Tests (Few)
/----\
/ \ Integration Tests (Some)
/--------\
/ \ Unit Tests (Many)
--------------
```
### Test Parallelization
```yaml
test:
parallel: 4
script:
- npm test -- --shard=$CI_NODE_INDEX/$CI_NODE_TOTAL
```
### Test Data Management
- Use fixtures for consistent test data
- Reset database state between tests
- Use factories for dynamic test data
- Avoid production data in tests
### Flaky Test Handling
```yaml
test:
retry:
max: 2
when:
- runner_system_failure
- stuck_or_timeout_failure
```
Strategies:
- Quarantine flaky tests
- Add retry logic for known issues
- Investigate and fix root causes
- Track flaky test metrics
## Monitoring and Observability
### Pipeline Metrics
Track these metrics:
- **Lead time**: Commit to production duration
- **Deployment frequency**: How often you deploy
- **Change failure rate**: Percentage of failed deployments
- **Mean time to recovery**: Time to fix failures
### Health Checks
```yaml
deploy:
script:
- ./deploy.sh
- ./wait-for-healthy.sh --timeout=300
- ./run-smoke-tests.sh
```
Implement:
- Readiness probes
- Liveness probes
- Startup probes
- Smoke tests post-deployment
### Alerting
```yaml
notify:failure:
stage: notify
script:
- ./send-alert.sh --channel=deployments --status=failed
when: on_failure
notify:success:
stage: notify
script:
- ./send-notification.sh --channel=deployments --status=success
when: on_success
```
## Security in CI/CD
### Secrets Management
```yaml
# Use CI/CD secret variables
deploy:
script:
- echo "$DEPLOY_KEY" | base64 -d > deploy_key
- chmod 600 deploy_key
- ./deploy.sh
after_script:
- rm -f deploy_key
```
Best practices:
- Rotate secrets regularly
- Use short-lived credentials
- Audit secret access
- Never log secrets
### Pipeline Security
```yaml
# Restrict who can run production deploys
deploy:production:
rules:
- if: $CI_COMMIT_BRANCH == "main"
when: manual
allow_failure: false
environment:
name: production
deployment_tier: production
```
Controls:
- Branch protection rules
- Required approvals
- Audit logging
- Signed commits
### Dependency Security
```yaml
dependency_check:
script:
- npm audit --audit-level=high
- ./check-licenses.sh
allow_failure: false
```
## Optimization Techniques
### Caching
```yaml
cache:
key:
files:
- package-lock.json
paths:
- node_modules/
policy: pull-push
```
Cache strategies:
- Cache dependencies between runs
- Use content-based cache keys
- Separate cache per branch
- Clean stale caches periodically
### Parallelization
```yaml
stages:
- build
- test
- deploy
# Run tests in parallel
test:unit:
stage: test
script: npm run test:unit
test:integration:
stage: test
script: npm run test:integration
test:e2e:
stage: test
script: npm run test:e2e
```
### Artifact Management
```yaml
build:
artifacts:
paths:
- dist/
expire_in: 1 week
when: on_success
```
Best practices:
- Set appropriate expiration
- Only store necessary artifacts
- Use artifact compression
- Clean up old artifacts
## Rollback Strategies
### Automatic Rollback
```yaml
deploy:
script:
- ./deploy.sh
- ./health-check.sh || ./rollback.sh
```
### Manual Rollback
```yaml
rollback:
stage: deploy
when: manual
script:
- ./get-previous-version.sh
- ./deploy.sh --version=$PREVIOUS_VERSION
```
### Database Rollbacks
- Use reversible migrations
- Test rollback procedures
- Consider data compatibility
- Have backup restoration process
## Documentation
### Pipeline Documentation
Document in your repository:
- Pipeline stages and their purpose
- Required environment variables
- Deployment procedures
- Troubleshooting guides
- Rollback procedures
### Runbooks
Create runbooks for:
- Deployment failures
- Rollback procedures
- Environment setup
- Incident response
## Continuous Improvement
### Metrics to Track
- Build success rate
- Average build time
- Test coverage trends
- Deployment frequency
- Incident frequency
### Regular Reviews
- Weekly pipeline performance review
- Monthly security assessment
- Quarterly process improvement
- Annual tooling evaluation
© Mindrally · Apache-2.0 · Mindrally/skills