Skip to main content

CircleCI + Bitbucket – Manual Single-File Integration

This guide shows how to run the Early Agent inside a CircleCI pipeline for a Bitbucket repository, generating tests for a single file using the generate-for-project command.

This workflow is designed for initial integration and validation before enabling automated PR or commit-based test generation.


🎯 Goal of This Phase​

The purpose of this setup is to:

  • Validate CI configuration and permissions
  • Ensure Early can run successfully in your environment
  • Confirm test generation works end-to-end
  • Avoid introducing automation too early

Test generation is intentionally scoped to one medium-sized file
(not too small to be trivial, and not too large to complicate validation).


🧩 How It Works​

At a high level, this pipeline:

  1. Checks out the repository
  2. Configures npm authentication
  3. Installs project dependencies
  4. Sets required environment variables
  5. Runs early generate-for-project on a single file
  6. Commits generated tests to the specified branch

Execution is manually triggered from CircleCI.


πŸ› οΈ Example CircleCI Configuration​

Below is a complete CircleCI configuration for manual, single-file integration:

version: 2.1

jobs:
earlyai-single-file-integration:
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 Early
no_output_timeout: 30m
command: |
export API_KEY="$EARLY_SECRET_TOKEN"
export TOKEN="$BB_ACCESS_TOKEN"
export SCM_PROVIDER="bitbucket"
export TARGET_DIRECTORY="src/path/to/file.ts"
export REF_NAME="$CIRCLE_BRANCH"
export GIT_USER_EMAIL="${BB_USER_EMAIL}"
export NODE_OPTIONS="--max-old-space-size=5120"

npx @earlyai/cli generate-for-project

workflows:
earlyai-manual-integration:
jobs:
- earlyai-single-file-integration:
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

βœ… Success Criteria​

This phase is considered successful when:

  • Test files are generated for the selected file
  • Generated tests are committed to the target branch
  • The pipeline completes without errors
  • Logs show coverage analysis and test generation steps

Once validated, you can safely move on to automated PR-based workflows.


πŸ” Next Step​

Proceed to Phase 2 and enable automated test generation:


This guide follows the general Integration Guide and adapts it specifically for CircleCI and Bitbucket.