Skip to content
Lovelace

CI/CD Integration

Run Ada tasks in continuous integration pipelines

Overview#

CI runners have no browser and no interactive terminal. ada auth login needs a browser or QR code device flow, and ada chat is interactive only, so neither runs in a pipeline. Pipelines use the local Lattice runtime instead: they configure it with an LLM provider API key stored as a CI secret, queue work with ada tasks submit, wait for it with ada tasks monitor --follow, and read the result with ada tasks get.

Pipeline Steps#

Every example on this page runs the same sequence:

bash
# 1. Install the Ada CLI and the Lattice runtime
curl -fsSL https://d.uselovelace.com/install | sh

# 2. Configure the provider; the key is read from ANTHROPIC_API_KEY
lattice-ctl init --provider anthropic --api-key-env ANTHROPIC_API_KEY

# 3. Start the daemon in the background
lattice-ctl daemon start

# 4. Create a workspace for the checkout
WORKSPACE_ID=$(ada workspaces init --format json | jq -r .id)

# 5. Queue a task and wait until it completes, fails, or is cancelled
TASK_ID=$(ada tasks submit "Review the changes between origin/main and HEAD for bugs, security issues, and missing tests" --workspace "$WORKSPACE_ID" --format json | jq -r .id)
ada tasks monitor "$TASK_ID" --follow

# 6. Save the task output
ada tasks get "$TASK_ID" --format json | jq -r '.output // empty' > ai-review.md

Details:

  • The installer detects CI. On GitHub Actions it installs into the runner tool cache and adds the binaries to GITHUB_PATH for later steps. On other CI systems it installs into /usr/local/bin. Set LOVELACE_INSTALL_DIR to install somewhere else and LOVELACE_VERSION to pin a version.

  • To use OpenAI instead, run lattice-ctl init --provider openai --api-key-env OPENAI_API_KEY.

  • ada tasks monitor --follow exits with status 0 whether the task completed or failed. To fail the job on a failed task, check the status field:

    bash
    test "$(ada tasks get "$TASK_ID" --format json | jq -r .status)" = "completed"
    
  • Run the steps in one shell session or one CI job so the background daemon stays available to the later commands.

GitHub Actions#

Create .github/workflows/ai-review.yml and add an ANTHROPIC_API_KEY repository secret:

yaml
name: AI Code Review

on:
  pull_request:

permissions:
  contents: read
  pull-requests: write

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Install the Ada CLI and the Lattice runtime
        run: curl -fsSL https://d.uselovelace.com/install | sh

      - name: Review the pull request
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
          BASE_REF: ${{ github.base_ref }}
        run: |
          lattice-ctl init --provider anthropic --api-key-env ANTHROPIC_API_KEY
          lattice-ctl daemon start
          WORKSPACE_ID=$(ada workspaces init --format json | jq -r .id)
          TASK_ID=$(ada tasks submit "Review the changes between origin/$BASE_REF and HEAD for bugs, security issues, and missing tests" --workspace "$WORKSPACE_ID" --format json | jq -r .id)
          ada tasks monitor "$TASK_ID" --follow
          ada tasks get "$TASK_ID" --format json | jq -r '.output // empty' > ai-review.md

      - name: Post the review as a comment
        env:
          GH_TOKEN: ${{ github.token }}
          PR_NUMBER: ${{ github.event.pull_request.number }}
        run: |
          if [ -s ai-review.md ]; then
            gh pr comment "$PR_NUMBER" --body-file ai-review.md
          fi

GitLab CI/CD#

Add ANTHROPIC_API_KEY as a masked CI/CD variable, then add this job to .gitlab-ci.yml:

yaml
ai-review:
  image: ubuntu:24.04
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
  before_script:
    - apt-get update && apt-get install -y ca-certificates curl git jq
    - curl -fsSL https://d.uselovelace.com/install | sh
  script:
    - git fetch origin "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
    - lattice-ctl init --provider anthropic --api-key-env ANTHROPIC_API_KEY
    - lattice-ctl daemon start
    - WORKSPACE_ID=$(ada workspaces init --format json | jq -r .id)
    - TASK_ID=$(ada tasks submit "Review the changes between origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME and HEAD for bugs, security issues, and missing tests" --workspace "$WORKSPACE_ID" --format json | jq -r .id)
    - ada tasks monitor "$TASK_ID" --follow
    - ada tasks get "$TASK_ID" --format json | jq -r '.output // empty' > ai-review.md
  artifacts:
    paths:
      - ai-review.md

Other CI Systems#

For Jenkins, CircleCI, Azure DevOps, and other systems, keep the steps in a script in the repository and call it from the pipeline. This version installs into the home directory so it works without root:

bash
#!/usr/bin/env bash
# scripts/ai-review.sh
set -euo pipefail

export LOVELACE_INSTALL_DIR="$HOME/.lovelace"
curl -fsSL https://d.uselovelace.com/install | sh
export PATH="$LOVELACE_INSTALL_DIR/bin:$PATH"

lattice-ctl init --provider anthropic --api-key-env ANTHROPIC_API_KEY
lattice-ctl daemon start

WORKSPACE_ID=$(ada workspaces init --format json | jq -r .id)
TASK_ID=$(ada tasks submit "Review the changes between ${REVIEW_BASE:-origin/main} and HEAD for bugs, security issues, and missing tests" --workspace "$WORKSPACE_ID" --format json | jq -r .id)
ada tasks monitor "$TASK_ID" --follow
ada tasks get "$TASK_ID" --format json | jq -r '.output // empty' > ai-review.md

Make the script executable with chmod +x scripts/ai-review.sh and commit it. The runner needs curl, git, and jq. Provide ANTHROPIC_API_KEY from the system's secret store.

Jenkins (Jenkinsfile, with a secret text credential named anthropic-api-key):

groovy
pipeline {
    agent any
    stages {
        stage('AI Review') {
            steps {
                withCredentials([string(credentialsId: 'anthropic-api-key', variable: 'ANTHROPIC_API_KEY')]) {
                    sh 'scripts/ai-review.sh'
                }
                archiveArtifacts artifacts: 'ai-review.md', allowEmptyArchive: true
            }
        }
    }
}

CircleCI (.circleci/config.yml, with ANTHROPIC_API_KEY set as a project environment variable):

yaml
version: 2.1

jobs:
  ai-review:
    docker:
      - image: cimg/base:current
    steps:
      - checkout
      - run: scripts/ai-review.sh
      - store_artifacts:
          path: ai-review.md

workflows:
  review:
    jobs:
      - ai-review

Azure DevOps (azure-pipelines.yml, with ANTHROPIC_API_KEY defined as a secret pipeline variable):

yaml
pool:
  vmImage: "ubuntu-latest"

steps:
  - checkout: self
    fetchDepth: 0

  - script: scripts/ai-review.sh
    displayName: "AI review"
    env:
      ANTHROPIC_API_KEY: $(ANTHROPIC_API_KEY)

  - publish: ai-review.md
    artifact: ai-review

Security#

  • Store provider API keys in the CI system's secret store and pass them as environment variables. lattice-ctl init --api-key-env reads the key from the environment; avoid --api-key, which puts the key on the command line.
  • Run AI review jobs on pull request events only, and give the job the smallest token permissions it needs (the GitHub example only needs pull-requests: write to comment).

Troubleshooting#

ada tasks submit prints Error: Daemon is not running

The daemon did not start or stopped between steps. When the daemon is not running, ada tasks submit falls back to the cloud task backend, which needs an interactive sign-in. Check and restart the daemon in the same job:

bash
lattice-ctl daemon status
lattice-ctl daemon start
lattice-ctl health

The task fails immediately

Check that the provider key reaches the daemon and that the provider is reachable:

bash
lattice-ctl provider test anthropic

ada or lattice-ctl is not found after installing

On CI systems other than GitHub Actions, add the install directory to PATH (see scripts/ai-review.sh above), or check where the installer put the binaries in its output.


See Also: