1. ai
  2. /building
  3. /ai-in-cicd

AI in CI/CD

CI/CD is where agent speed meets production gates — useful for review comments and failure triage, dangerous when agents merge or deploy without human approval.

Last reviewed: June 2026

GitHub Actions, Codex Action, and Claude Code SDK APIs change frequently. Pin action SHAs and verify vendor docs before org-wide rollout.

What to automate vs not

Automate (non-blocking)Keep human-gated
PR review commentsMerge approval
Suggest test casesProduction deploy
Summarize failure logsSchema migrations
Label ai-assisted PRsSecret rotation
Lint/format suggestions on bot branchesInfrastructure Terraform apply

Policy belongs in Team AI Policy and AI Code Review.

Common patterns

PR review bot (comment-only)

# .github/workflows/ai-review.yml (illustrative — pin exact action version)
name: AI Review
on:
  pull_request:
    types: [opened, synchronize]

jobs:
  review:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
      contents: read
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Run review tool
        env:
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
        run: |
          # Vendor CLI or custom script — posts comments, does not approve
          echo "Run org-approved review CLI here"

Never store API keys in workflow files. Use GitHub Secrets. Comments only — do not set required checks on AI alone.

Failure triage on CI red

On test failure, post workflow summary with AI-generated hypothesis:

  1. Capture failed job log (truncate to token budget)
  2. Send to API with structured output — see Structured Outputs
  3. Post summary as job annotation or PR comment
  4. Developer verifies — AI does not auto-fix on main

Claude Code / Codex in CI

ToolCI fit
Codex GitHub ActionPR review comments (verify current action)
Claude Code SDKCustom pipelines — script headless agent with scoped repo checkout
AiderRare in CI — better interactive

Headless agents need read-only checkout and explicit file allowlists.

Security in CI

RiskMitigation
Secret leak in logsMask secrets; redact tool output
Fork PR exfiltrationDo not run AI on external forks with secrets
Prompt injection via PR title/bodySanitize; system prompt ignores instruction overrides
Over-privileged GITHUB_TOKENMinimum permissions per job
Supply chainPin action SHAs; vet third-party review actions

See MCP Security if CI agents use MCP.

Context limits in CI

SourceToken cost
Full monorepoToo large — use diff only
git diff main...HEADPreferred for review
Failed test log (last 200 lines)Enough for triage
AGENTS.mdInclude for stack context

See Context Engineering.

Observability

Log per run:

  • Model ID and token usage
  • Job URL and PR number
  • Outcome (comment posted / skipped / error)

Route to same dashboards as product LLM features — LLM Observability.

Production concerns

ConcernWhat to do
CostTrigger on PR open/sync only; skip draft PRs
LatencyAsync jobs; do not block merge on AI
Flaky AIRetry once; fail open (no comment) vs fail closed
ComplianceEnterprise API plans; zero retention contracts