Skip to main content

Jenkins + GitHub – Commit Test Generation

This example shows how to run the Early Agent inside a Jenkins pipeline for a GitHub repository, generating tests automatically on commits using the generate-commit command.

The pipeline:

  • Runs on commits (branch-based)
  • Installs project dependencies
  • Configures authentication
  • Invokes Early to generate and commit tests back to the same branch

This setup is intentionally minimal and can be adapted to your existing Jenkins pipelines.


🧩 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-commit on the current branch

Early detects changed files since the last commit, evaluates coverage, and generates tests where needed.


🛠️ Example Jenkinsfile

Below is a declarative Jenkins pipeline that integrates Early with GitHub:

pipeline {
agent {
docker {
image 'node:22'
args '-u root'
}
}

environment {
API_KEY = credentials('EARLY_SECRET_TOKEN')
TOKEN = credentials('GITHUB_TOKEN')
REF_NAME = ${env.BRANCH_NAME} // Git branch name for commit
SCM_PROVIDER = 'github'
GIT_USER_EMAIL = credentials('GIT_USER_EMAIL')
NODE_OPTIONS = '--max-old-space-size=5120'
}

stages {
stage('Checkout') {
steps {
checkout scm
}
}

stage('Setup npm auth') {
steps {
sh '''
echo "//npm.pkg.github.com/:_authToken=${TOKEN}" >> ~/.npmrc
echo "@earlyai:registry=https://npm.pkg.github.com" >> ~/.npmrc
'''
}
}

stage('Install dependencies') {
steps {
sh 'npm clean-install'
}
}

stage('Run Early Agent') {
steps {
sh '''
npx @earlyai/cli generate-commit
'''
}
}
}
}

🔐 Required Jenkins Credentials

This example assumes the following credentials are configured in Jenkins:

  • EARLY_SECRET_TOKEN – Early API key
  • GITHUB_TOKEN – GitHub token with repo access
  • GIT_USER_EMAIL – Email address used for committing generated tests

✅ Notes

  • The pipeline runs on commits pushed to the branch.
  • Generated tests are committed back to the same branch.
  • The GitHub token is used both for repo access and npm authentication.
  • Memory limits are increased to support larger repositories.

This guide follows the general Integration Guide and adapts it specifically for Jenkins and GitHub.