Skip to main content

๐Ÿ”— 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 key
  • TOKEN โ†’ SCM token (e.g., GitHub PAT, Bitbucket App Password) โ†’ See SCM Support and Token Permissions
  • HEAD_REF / BASE_REF โ†’ Branch names (if using PR mode)
  • SCM_PROVIDER โ†’ e.g., github or bitbucket
  • Optional: AUTO_COMMIT, MAX_CONCURRENCY, NODE_OPTIONS, LINT_COMMAND

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โ€‹

CodeMeaning
0Success
1Configuration or environment issue
2Generation or validation failure
3Commit/push failure


๐Ÿงต Next Stepsโ€‹