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
- Configures npm authentication for Early
- 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: Setup npm auth
command: |
echo "//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}" >> ~/.npmrc
echo "@earlyai:registry=https://npm.pkg.github.com" >> ~/.npmrc
- run:
name: Install dependencies
command: npm clean-install
- run:
name: Setup environment variables and run EarlyAI
no_output_timeout: 30m
command: |
export API_KEY="$EARLY_SECRET_TOKEN"
export TOKEN="$BB_ACCESS_TOKEN"
export SCM_PROVIDER="bitbucket"
export PR_NUMBER="$(basename "$CIRCLE_PULL_REQUEST")"
export REF_NAME="$CIRCLE_BRANCH"
export GIT_USER_EMAIL="${BB_USER_EMAIL}"
export NODE_OPTIONS="--max-old-space-size=5120"
npx @earlyai/cli generate-pr
workflows:
earlyai-workflow:
jobs:
- earlyai-test-generation:
context: early-ci
π 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 commitsGITHUB_TOKENβ Token for accessing Earlyβs npm package
β 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.