CircleCI + Bitbucket – PR Test Generation
This example shows how to run the Early Agent inside a CircleCI pipeline for a Bitbucket repository, generating tests automatically for pull requests using the generate-pr command.
The pipeline:
- Runs on pull requests
- Installs project dependencies
- Configures authentication
- Invokes Early to generate and commit tests back to the PR branch
This setup is intentionally minimal and can be adapted to your existing CI workflow.
🧩 How It Works
At a high level, the pipeline performs the following steps:
- Checks out the repository
- Installs dependencies
- Sets required environment variables
- Runs
early generate-pragainst the active pull request
Early detects changed files in the PR, evaluates coverage, and generates tests where needed.
🛠️ Example CircleCI Configuration
Below is a complete CircleCI configuration that integrates Early with Bitbucket:
version: 2.1
jobs:
earlyai-test-generation:
docker:
- image: cimg/node:22.19
steps:
- checkout
- run:
name: Install dependencies
command: npm ci
- run:
name: Setup environment variables and run EarlyAI
command: |
export NODE_OPTIONS="--max-old-space-size=6144"
export SCM_PROVIDER="bitbucket"
export API_KEY="$EARLY_SECRET_TOKEN"
export REF_NAME="$CIRCLE_BRANCH"
export TOKEN="$BB_ACCESS_TOKEN"
export GIT_USER_EMAIL="$BB_USER_EMAIL"
export TEST_COMMAND="nx test --skip-nx-cache --coverage=false \$early_filename --json --silent"
export COVERAGE_COMMAND="nx test --skip-nx-cache --coverage --coverageProvider=v8 --coverageReporters=json --coverageDirectory=\$early_coverage_dir --silent --passWithNoTests"
export PR_NUMBER="$(basename "$CIRCLE_PULL_REQUEST")"
npx @earlyai/cli generate-pr
workflows:
earlyai-workflow:
jobs:
- earlyai-test-generation:
context: early
filters:
branches:
ignore:
- master
🔐 Required Secrets & Context
This example assumes the following environment variables are provided via a CircleCI context or project settings:
EARLY_SECRET_TOKEN– Early API keyBB_ACCESS_TOKEN– Bitbucket access tokenBB_USER_EMAIL– Email used for commits
✅ Notes
- The job uses the Bitbucket SCM provider explicitly.
PR_NUMBERis derived fromCIRCLE_PULL_REQUEST.- Generated tests are committed back to the PR branch.
- Memory limits are increased to support large repositories.
This guide follows the general Integration Guide and adapts it specifically for CircleCI and BitBucket.