Skip to content
Latchkey

How to Set Up Split in a CI Pipeline

Give the Split SDK the server-side API key and wait for SDK_READY before calling getTreatment.

Split evaluates named treatments per key. In CI, pass the server-side SDK key as a secret and wait for SDK_READY, otherwise getTreatment returns control.

Steps

  • Store the server-side SDK key as a repository secret.
  • Create the factory and client with that key.
  • Await SDK_READY before calling getTreatment.

Initialize the client

Terminal
const { SplitFactory } = require('@splitsoftware/splitio');
const factory = SplitFactory({
  core: { authorizationKey: process.env.SPLIT_API_KEY },
});
const client = factory.client();
client.on(client.Event.SDK_READY, () => {
  const t = client.getTreatment('ci-user', 'new-checkout');
  console.log('treatment:', t);
});

Pass the key in CI

.github/workflows/ci.yml
jobs:
  test:
    runs-on: ubuntu-latest
    env:
      SPLIT_API_KEY: ${{ secrets.SPLIT_API_KEY }}
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm test

Gotchas

  • A control treatment means the SDK was not ready or the split does not exist.
  • Call client.destroy() so buffered impressions flush before the job ends.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →