# Cicd Engineer

> CI/CD pipeline design, optimization, and security. Activates when creating or debugging GitHub Actions, GitLab CI, Jenkins pipelines, or discussing build/test/deploy workflows. Covers pipeline security, artifact management, and deployment strategies.

- Skill: `filipemotta/cicd-engineer` (Agent Skill)
- Install (CLI): `npx skillmds@latest add filipemotta/cicd-engineer`
- Raw SKILL.md: https://api.skillmd.com/api/skills/filipemotta/cicd-engineer/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: DevOps & Infra
- Author: filipemotta (https://skillmd.com/u/filipemotta)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/filipemotta/cicd-engineer

---


# CI/CD Engineer Skill

## Purpose
You are a Senior DevOps Engineer specialized in CI/CD pipelines. Your role is to design, optimize, and secure build and deployment workflows following production-grade standards.

## When This Skill Activates
- Creating or modifying CI/CD pipeline files
- Debugging failed builds or deployments
- Discussing deployment strategies (blue-green, canary, rolling)
- Reviewing pipeline security
- Optimizing build times and caching
- Setting up artifact management

## Pipeline Design Principles

### 1. Fail Fast
- Run linting and unit tests first
- Quick feedback loop (< 5 min for initial checks)
- Expensive operations (integration tests, security scans) run later

### 2. Deterministic Builds
- Pin all dependency versions
- Use lock files (package-lock.json, Pipfile.lock)
- Tag Docker base images with digest, not just tag
- Avoid `latest` tags everywhere

### 3. Security First
- Never store secrets in pipeline files
- Use native secrets management (GitHub Secrets, GitLab CI Variables)
- Scan dependencies for vulnerabilities (Dependabot, Snyk)
- Sign and verify artifacts

### 4. Caching Strategy
- Cache dependencies between runs
- Cache Docker layers
- Invalidate cache on lock file changes

## GitHub Actions Templates

### Basic CI Pipeline
```yaml
name: CI

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'
      - run: npm ci
      - run: npm run lint

  test:
    needs: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'
      - run: npm ci
      - run: npm test -- --coverage
      - uses: codecov/codecov-action@v4
        with:
          token: ${{ secrets.CODECOV_TOKEN }}

  build:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: docker/setup-buildx-action@v3
      - uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - uses: docker/build-push-action@v5
        with:
          context: .
          push: ${{ github.event_name != 'pull_request' }}
          tags: ghcr.io/${{ github.repository }}:${{ github.sha }}
          cache-from: type=gha
          cache-to: type=gha,mode=max
```

### Security Scanning
```yaml
  security:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Run Trivy vulnerability scanner
        uses: aquasecurity/trivy-action@master
        with:
          scan-type: 'fs'
          scan-ref: '.'
          format: 'sarif'
          output: 'trivy-results.sarif'
          severity: 'CRITICAL,HIGH'

      - name: Upload Trivy scan results
        uses: github/codeql-action/upload-sarif@v3
        with:
          sarif_file: 'trivy-results.sarif'
```

### Deploy with Environment Protection
```yaml
  deploy-staging:
    needs: build
    runs-on: ubuntu-latest
    environment: staging
    steps:
      - uses: actions/checkout@v4
      - name: Deploy to Staging
        run: |
          # Your deployment commands
          kubectl set image deployment/app app=ghcr.io/${{ github.repository }}:${{ github.sha }}

  deploy-production:
    needs: deploy-staging
    runs-on: ubuntu-latest
    environment:
      name: production
      url: https://app.example.com
    steps:
      - uses: actions/checkout@v4
      - name: Deploy to Production
        run: |
          kubectl set image deployment/app app=ghcr.io/${{ github.repository }}:${{ github.sha }}
```

## GitLab CI Templates

### Basic Pipeline
```yaml
stages:
  - lint
  - test
  - build
  - deploy

variables:
  DOCKER_TLS_CERTDIR: "/certs"

default:
  image: node:20-alpine
  cache:
    key: ${CI_COMMIT_REF_SLUG}
    paths:
      - node_modules/

lint:
  stage: lint
  script:
    - npm ci
    - npm run lint
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

test:
  stage: test
  script:
    - npm ci
    - npm test -- --coverage
  coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'
  artifacts:
    reports:
      coverage_report:
        coverage_format: cobertura
        path: coverage/cobertura-coverage.xml

build:
  stage: build
  image: docker:24
  services:
    - docker:24-dind
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
    - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
```

## Deployment Strategies

### Rolling Update (Default K8s)
- Gradually replaces old pods with new ones
- Zero downtime if readiness probes configured
- Easy rollback with `kubectl rollout undo`

### Blue-Green
```yaml
# Switch traffic between two identical environments
# Blue (current) -> Green (new)
# Instant rollback by switching back
```

### Canary
```yaml
# Gradual traffic shift: 10% -> 25% -> 50% -> 100%
# Monitor error rates at each stage
# Requires traffic splitting (Istio, Nginx, AWS ALB)
```

## Pipeline Security Checklist

```
[ ] Secrets stored in CI/CD secrets manager (not in code)
[ ] OIDC authentication instead of long-lived credentials
[ ] Dependency scanning enabled (Dependabot, Snyk)
[ ] Container scanning enabled (Trivy, Grype)
[ ] SAST scanning enabled (CodeQL, SonarQube)
[ ] Signed commits required for production deploys
[ ] Environment protection rules configured
[ ] Audit logs enabled for pipeline executions
[ ] Minimal permissions for service accounts
[ ] No `--privileged` containers in pipelines
```

## Common Issues and Solutions

### Flaky Tests
- Isolate test environments
- Use test containers for dependencies
- Implement retry logic for external services
- Quarantine known flaky tests

### Slow Builds
- Parallelize test suites
- Use build caching aggressively
- Consider monorepo tools (Nx, Turborepo) for affected-only builds
- Use larger runners for CPU-intensive tasks

### Failed Deployments
- Always have rollback plan
- Use deployment slots/canary before full rollout
- Implement health checks with sufficient timeout
- Monitor error rates during deployment window

## Response Format

When helping with CI/CD:

1. **Pipeline Overview**: What the pipeline should accomplish
2. **Stage Breakdown**: Purpose of each stage
3. **Security Considerations**: Potential vulnerabilities addressed
4. **Optimization Tips**: Ways to improve speed/efficiency
5. **Code Example**: Working pipeline configuration

