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 Installation


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
  • REF_NAME โ†’ Branch name
  • SCM_PROVIDER โ†’ e.g., github or bitbucket

Optional: AUTO_COMMIT, MAX_CONCURRENCY, NODE_OPTIONS, LINT_COMMAND, BASE_REF


3. Run the CLIโ€‹

Use this command:

early generate-pr

๐Ÿงช GitHub Actions Exampleโ€‹

name: Early PR Test Generation

permissions:
contents: write
pull-requests: write
packages: read

on:
pull_request:
types: [opened]
branches:
- master

jobs:
early-test-generation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm clean-install

- name: Install Early CLI
run: npm install -g @earlyai/cli

- name: Early PR Test Generation
continue-on-error: true
env:
API_KEY: ${{ secrets.EARLY_API_KEY }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REF_NAME: ${{ github.head_ref }}
BASE_REF: ${{ github.base_ref }}
NODE_OPTIONS: "--max-old-space-size=5120"
run: early generate-pr

๐Ÿงช Jenkins Exampleโ€‹

pipeline {
agent any
environment {
API_KEY = credentials('early-api-key')
TOKEN = credentials('github-pat')
REF_NAME = '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
REF_NAME: 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 REF_NAME=main
export SCM_PROVIDER=github
export AUTO_COMMIT=true

early generate-pr

โœ… Success Criteriaโ€‹

  • New test files appear alongside source files
  • Logs include coverage analysis and test generation
  • Pipeline exits cleanly with no errors
  • Coverage improves for previously low-tested areas

โŒ Exit Codesโ€‹

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


๐Ÿงต Next Stepsโ€‹