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_READYbefore callinggetTreatment.
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 testGotchas
- A
controltreatment 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
How to Set Up LaunchDarkly in a CI PipelineWire LaunchDarkly into GitHub Actions by passing the SDK key as a secret and initializing the client so tests…
How to Run an A/B Test With Feature FlagsSplit traffic between a control and a variant with a feature flag and log the assigned variation, so an A/B t…