Skip to content
Latchkey

Buildkite BUILDKITE_PARALLEL_JOB not set in CI

When a step sets parallelism, Buildkite exposes BUILDKITE_PARALLEL_JOB (0-based index) and BUILDKITE_PARALLEL_JOB_COUNT to each copy. Without parallelism, these are unset and any test-splitting logic breaks.

What this error means

A test-splitting command reads an empty BUILDKITE_PARALLEL_JOB, so it runs the whole suite on one node or errors on an empty index.

buildkite
$ echo "shard $BUILDKITE_PARALLEL_JOB of $BUILDKITE_PARALLEL_JOB_COUNT"
shard  of
Error: parallel job index is empty

Common causes

The step did not declare parallelism

Without a parallelism: value on the step, Buildkite runs a single copy and never sets the parallel-job env vars.

Splitting logic assumes the vars always exist

A script reads BUILDKITE_PARALLEL_JOB directly and fails when the step is not parallelized.

How to fix it

Declare parallelism on the step

  1. Add parallelism: with the number of shards to the step.
  2. Read BUILDKITE_PARALLEL_JOB and BUILDKITE_PARALLEL_JOB_COUNT in the split command.
  3. Re-run so each copy gets its index.
pipeline.yml
steps:
  - label: "test"
    command: "./scripts/run-shard.sh"
    parallelism: 5

Default the index when not parallelized

Guard the split so a non-parallel run still works by defaulting the index and count.

Terminal
INDEX="${BUILDKITE_PARALLEL_JOB:-0}"
COUNT="${BUILDKITE_PARALLEL_JOB_COUNT:-1}"

How to prevent it

  • Set parallelism on any step that shards work.
  • Default the parallel index/count in split scripts.
  • Keep shard count and the split logic in sync.

Related guides

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