๐ Integrating the Early CLI in Any CI/CD
The Early CLI lets you run AI-powered test generation on any CI/CD platform โ Jenkins, CircleCI, GitLab CI, Bitbucket Pipelines, and more.
It mirrors the GitHub Action's logic and behavior but runs as a standalone CLI.
๐ฆ Setup Overviewโ
To get started, follow these steps:
1. Install the CLIโ
npm install -g @earlyai/cli
โ See NPM Authentication
2. Configure Required Inputsโ
All inputs are passed as environment variables:
API_KEYโ Your Early API keyTOKENโ SCM token (e.g., GitHub PAT, Bitbucket App Password) โ See SCM Support and Token PermissionsHEAD_REF/BASE_REFโ Branch names (if using PR mode)SCM_PROVIDERโ e.g.,githuborbitbucket- Optional:
AUTO_COMMIT,MAX_CONCURRENCY,NODE_OPTIONS,LINT_COMMAND- See Memory Tuning
- See Lint & Formatting
3. Run the CLIโ
Use one of the following commands depending on the agent mode:
early generate-pr
early generate-commit
early generate-folder
๐งช Jenkins Exampleโ
pipeline {
agent any
environment {
API_KEY = credentials('early-api-key')
TOKEN = credentials('github-pat')
HEAD_REF = 'feature-branch'
BASE_REF = 'main'
SCM_PROVIDER = 'github'
AUTO_COMMIT = 'true'
NODE_OPTIONS = '--max-old-space-size=5120'
LINT_COMMAND = 'npx --no eslint $early_filename --fix'
PRETTIER_COMMAND = 'npx --no prettier $early_filename --write'
}
stages {
stage('Install CLI') {
steps {
sh 'npm install -g @earlyai/cli'
}
}
stage('Run CLI') {
steps {
sh 'early generate-pr'
}
}
}
}
๐ CircleCI Exampleโ
jobs:
generate-tests:
docker:
- image: cimg/node:20.5
steps:
- checkout
- run:
name: Install CLI
command: npm install -g @earlyai/cli
- run:
name: Generate Tests
command: early generate-pr
environment:
API_KEY: $EARLY_API_KEY
TOKEN: $GITHUB_TOKEN
HEAD_REF: $CIRCLE_BRANCH
BASE_REF: main
SCM_PROVIDER: github
AUTO_COMMIT: true
NODE_OPTIONS: "--max-old-space-size=5120"
LINT_COMMAND: "npx --no eslint $early_filename --fix"
PRETTIER_COMMAND: "npx --no prettier $early_filename --write"
๐ป Local Run Exampleโ
export API_KEY=xxx
export TOKEN=xxx
export HEAD_REF=my-branch
export BASE_REF=main
export SCM_PROVIDER=github
export AUTO_COMMIT=true
early generate-pr
โ Exit Codesโ
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Configuration or environment issue |
| 2 | Generation or validation failure |
| 3 | Commit/push failure |