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 emptyCommon 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
- Add
parallelism:with the number of shards to the step. - Read
BUILDKITE_PARALLEL_JOBandBUILDKITE_PARALLEL_JOB_COUNTin the split command. - Re-run so each copy gets its index.
pipeline.yml
steps:
- label: "test"
command: "./scripts/run-shard.sh"
parallelism: 5Default 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
parallelismon any step that shards work. - Default the parallel index/count in split scripts.
- Keep shard count and the split logic in sync.
Related guides
Buildkite job stuck "Waiting for agent" forever in CIFix a Buildkite job stuck on "Waiting for agent" in CI - no agent with capacity and matching tags is availabl…
Buildkite "meta-data get: key not found" in CIFix Buildkite "buildkite-agent meta-data get: key not found" in CI - a step read a meta-data key that no earl…
Buildkite "command exited with status 1" in CIFix Buildkite "The command exited with status 1" in CI - a step command returned a non-zero exit code, so Bui…