Skip to content

CI Integration

Copy-paste examples for GitHub Actions, GitLab CI, and Jenkins.

Every example below uses af run to execute your test command, automatically create a test run, detect JUnit XML output, upload results, and finish the run — all in a single step. Your test framework just needs to produce JUnit XML (most do by default or with a flag).

GitHub Actions

name: Tests
on: [push]

jobs:
  test:
    runs-on: ubuntu-latest
    env:
      AF_API_KEY: ${{ secrets.AF_API_KEY }}
      AF_PROJECT_ID: ${{ secrets.AF_PROJECT_ID }}
    steps:
      - uses: actions/checkout@v4

      - name: Install AF CLI
        run: |
          curl -fsSL https://cli.automatedfuture.co/cli/install.sh | sh
          echo "$HOME/.local/bin" >> $GITHUB_PATH

      - name: Configure AF
        run: af config from-env

      - name: Run tests
        run: af run --label "CI #${{ github.run_number }}" -- npm test -- --reporter=junit

Add AF_API_KEY and AF_PROJECT_ID as secrets in Settings > Secrets and variables > Actions.

The install step uses $GITHUB_PATH so that af is available in all subsequent steps without repeating export PATH=....


GitLab CI

test:
  image: ubuntu:24.04
  before_script:
    - apt-get update && apt-get install -y curl
    - curl -fsSL https://cli.automatedfuture.co/cli/install.sh | sh
    - export PATH="$HOME/.local/bin:$PATH"
    - af config from-env
  script:
    - af run --label "GitLab CI #$CI_PIPELINE_IID" -- pytest --junitxml=results.xml

Add AF_API_KEY and AF_PROJECT_ID as CI/CD variables in Settings > CI/CD > Variables (enable Masked for AF_API_KEY). GitLab automatically injects them as environment variables into every job.

before_script and script run in the same shell, so the PATH export persists into script.


Jenkins

pipeline {
  agent any
  environment {
    AF_API_KEY    = credentials('af-api-key')
    AF_PROJECT_ID = credentials('af-project-id')
  }
  stages {
    stage('Setup') {
      steps {
        sh 'curl -fsSL https://cli.automatedfuture.co/cli/install.sh | sh'
        sh 'export PATH="$HOME/.local/bin:$PATH" && af config from-env'
      }
    }
    stage('Test') {
      steps {
        sh '''
          export PATH="$HOME/.local/bin:$PATH"
          af run --label "Jenkins #$BUILD_NUMBER" -- ./gradlew test
        '''
      }
    }
  }
}

Add af-api-key and af-project-id as Secret text credentials in Manage Jenkins > Credentials. Each sh step runs in a separate shell, so PATH must be exported in every step that calls af.


Test Framework Setup

See the Test Frameworks page for detailed setup guides for Jest, pytest, Playwright, Go, Rust, RSpec, PHPUnit, and more.


Environment Variables

VariableRequiredDescription
AF_API_KEYYesYour API key (from Dashboard > Team > API Keys)
AF_PROJECT_IDRecommendedDefault project ID — avoids passing --project-id to every command

Run af config from-env after setting these to load them into the CLI config.


Troubleshooting

af: command not found — The install directory (~/.local/bin) is not in your PATH. Add export PATH="$HOME/.local/bin:$PATH" before calling af, or use echo "$HOME/.local/bin" >> $GITHUB_PATH in GitHub Actions.

Invalid API key — Double-check the secret is set correctly in your CI platform and that the key has not been revoked.

No JUnit XML files found — Make sure your test framework is configured to output JUnit XML. If the output path is non-standard, pass it explicitly with --junit path/to/results.xml.

Need help? Email support@automatedfuture.co.