Skip to main content

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:

  1. Checks out the repository
  2. Configures npm authentication for Early
  3. Installs dependencies
  4. Sets required environment variables
  5. Runs early generate-pr against 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 key
  • BB_ACCESS_TOKEN – Bitbucket access token
  • BB_USER_EMAIL – Email used for commits
  • GITHUB_TOKEN – Token for accessing Early’s npm package

βœ… Notes​

  • The job uses the Bitbucket SCM provider explicitly.
  • PR_NUMBER is derived from CIRCLE_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.