The Complete Guide to Building CI/CD Pipelines with Claude Code
A comprehensive guide to building ci/cd pipelines using Claude Code with practical examples and best practices.
Streamline CI/CD Pipeline Setup with Claude Code
CI/CD configuration files have many intricate syntax requirements and often require time-consuming trial and error. With Claude Code, you can generate pipelines tailored to your project in one shot.
Basic GitHub Actions Workflow
> Create a GitHub Actions workflow.
> - Run lint, type checking, and tests when a PR is created
> - Build and deploy when merged to main
> - Use Node.js 20 and pnpm
> - Configure caching for faster runs
# .github/workflows/ci.yml
name: CI
on:
pull_request:
branches: [main]
push:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Lint
run: pnpm lint
- name: Type Check
run: pnpm tsc --noEmit
- name: Test
run: pnpm test -- --coverage
- name: Upload Coverage
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage/
deploy:
needs: lint-and-test
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm build
- name: Deploy to Vercel
uses: amondnet/vercel-action@v25
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
vercel-args: --prod
Docker Image Build and Push
> Create a workflow that builds a Docker image
> and pushes it to GitHub Container Registry.
> Tag with the git tag and commit SHA.
# .github/workflows/docker.yml
name: Docker Build
on:
push:
tags: ["v*"]
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
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/metadata-action@v5
id: meta
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=sha,prefix=
- uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
For setting up Docker environments, see the Docker Integration Guide.
Integrating E2E Tests
> Integrate Playwright E2E tests into CI/CD.
> Save screenshots on test failures.
e2e-test:
needs: lint-and-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: npx playwright install --with-deps chromium
- name: Run E2E Tests
run: pnpm test:e2e
- uses: actions/upload-artifact@v4
if: failure()
with:
name: playwright-report
path: playwright-report/
retention-days: 7
For the overall testing strategy, see the Complete Testing Strategy Guide. For Git workflow integration, also check out Fully Automating Git Operations.
Adding Security Scans
> Add dependency vulnerability scanning to CI.
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npx audit-ci --moderate
For more on security checks, see Automating Security Audits.
Summary
With Claude Code, you can build CI/CD pipelines optimized for your project in no time. By clearly specifying each stage — lint, test, build, and deploy — you get production-ready workflows generated for you.
For GitHub Actions details, refer to the official GitHub Actions documentation. For Claude Code, see the official Anthropic documentation.
Related Posts
Mastering Claude Code Hooks: Auto-Format, Auto-Test, and More
Mastering Claude Code Hooks: Auto-Format, Auto-Test, and More. A practical guide with code examples.
Claude Code MCP Server Setup and Practical Use Cases
Claude Code MCP Server Setup and Practical Use Cases. A practical guide with code examples.
The Complete Guide to Writing CLAUDE.md: Best Practices for Project Configuration
The Complete Guide to Writing CLAUDE.md: Best Practices for Project Configuration. A practical guide with code examples.