CI/CD Pipelines Advanced
Integrate Claude Code into your continuous integration and delivery pipelines. Automate code reviews, generate tests, create PR descriptions, and produce documentation — all triggered by git events.
GitHub Actions Integration
Add Claude Code as a step in your GitHub Actions workflow for automated code review on every pull request:
YAML (.github/workflows/claude-review.yml)
name: Claude Code Review on: pull_request: types: [opened, synchronize] jobs: review: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20' - name: Install Claude Code run: npm install -g @anthropic-ai/claude-code - name: Run Claude Code Review env: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} run: | DIFF=$(git diff origin/main...HEAD) REVIEW=$(echo "$DIFF" | claude -p "Review this pull request diff. Focus on bugs, security issues, and performance problems. Format as markdown.") echo "$REVIEW" > review.md - name: Post Review Comment uses: actions/github-script@v7 with: script: | const fs = require('fs'); const review = fs.readFileSync('review.md', 'utf8'); github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: '## AI Code Review\n\n' + review });
Automated Test Generation
YAML (.github/workflows/claude-tests.yml)
name: Generate Tests for New Code on: pull_request: paths: - 'src/**/*.ts' - 'src/**/*.js' jobs: generate-tests: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: actions/setup-node@v4 with: node-version: '20' - run: npm install -g @anthropic-ai/claude-code - name: Generate tests for changed files env: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} run: | CHANGED_FILES=$(git diff --name-only origin/main...HEAD -- 'src/*.ts' 'src/*.js') for file in $CHANGED_FILES; do echo "Generating tests for $file" claude -p "Generate comprehensive unit tests for $file. Use Jest. Write tests to __tests__/ directory." done - name: Run new tests run: npm test - name: Commit generated tests run: | git config user.name "Claude Code Bot" git config user.email "claude-bot@example.com" git add __tests__/ git diff --cached --quiet || git commit -m "test: add AI-generated tests for new code" git push
GitLab CI Integration
YAML (.gitlab-ci.yml)
stages: - review - test - deploy claude-review: stage: review image: node:20-slim before_script: - npm install -g @anthropic-ai/claude-code - apt-get update && apt-get install -y git script: - | DIFF=$(git diff origin/main...HEAD) echo "$DIFF" | claude -p "Review this merge request. Identify issues and suggest improvements." > review.txt cat review.txt variables: ANTHROPIC_API_KEY: $ANTHROPIC_API_KEY only: - merge_requests artifacts: paths: - review.txt expire_in: 1 week claude-docs: stage: review image: node:20-slim before_script: - npm install -g @anthropic-ai/claude-code script: - claude -p "Generate API documentation for all new endpoints added in the latest commits" > docs/api-update.md variables: ANTHROPIC_API_KEY: $ANTHROPIC_API_KEY only: - merge_requests artifacts: paths: - docs/
Jenkins Pipeline
Groovy (Jenkinsfile)
pipeline { agent { docker { image 'node:20-slim' } } environment { ANTHROPIC_API_KEY = credentials('anthropic-api-key') } stages { stage('Setup') { steps { sh 'npm install -g @anthropic-ai/claude-code' } } stage('AI Code Review') { steps { sh ''' DIFF=$(git diff HEAD~1) echo "$DIFF" | claude -p "Review this code change for bugs and security issues" > review.txt ''' archiveArtifacts artifacts: 'review.txt' } } stage('Generate PR Description') { steps { sh ''' git log --oneline HEAD~5..HEAD | claude -p "Write a professional PR description summarizing these commits" > pr-description.md ''' } } } post { always { cleanWs() } } }
PR Description Generation
Automatically generate professional pull request descriptions:
YAML (.github/workflows/pr-description.yml)
name: Auto PR Description on: pull_request: types: [opened] jobs: describe: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: actions/setup-node@v4 with: node-version: '20' - run: npm install -g @anthropic-ai/claude-code - name: Generate description env: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} run: | DIFF=$(git diff origin/main...HEAD) COMMITS=$(git log --oneline origin/main...HEAD) DESCRIPTION=$(echo -e "Commits:\n$COMMITS\n\nDiff:\n$DIFF" | claude -p "Write a comprehensive PR description with: Summary, Changes Made, Testing Done, and Breaking Changes sections. Use markdown.") echo "$DESCRIPTION" > pr-body.md - name: Update PR body uses: actions/github-script@v7 with: script: | const fs = require('fs'); const body = fs.readFileSync('pr-body.md', 'utf8'); github.rest.pulls.update({ owner: context.repo.owner, repo: context.repo.repo, pull_number: context.issue.number, body: body });
Documentation Generation in CI
YAML (.github/workflows/docs.yml)
name: Generate Documentation on: push: branches: [main] paths: - 'src/**' jobs: docs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: '20' - run: npm install -g @anthropic-ai/claude-code - name: Generate docs env: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} run: | claude -p "Generate comprehensive API documentation for all files in src/routes/. Output as markdown to docs/api/" claude -p "Update the README.md with any new features based on recent changes" - name: Commit docs run: | git config user.name "Claude Docs Bot" git config user.email "docs-bot@example.com" git add docs/ README.md git diff --cached --quiet || git commit -m "docs: auto-update documentation" git push
Cost Control: CI/CD pipelines can run frequently. Use the
--max-turns flag to limit Claude's actions per run, and consider running expensive analyses only on PRs to main (not feature branches).
Try It Yourself
Set up a GitHub Actions workflow that runs Claude Code review on your pull requests. Start with the basic review template above. Next, explore cloud development environments.
Next: Cloud Development →
Lilly Tech Systems