A way to get the index of a concurrency group?

We have a set of shared resources that we want to access in our build jobs, and concurrency groups seem like the ideal way to make sure that we don’t exceed our maximum number of simultaneous jobs.

However, ideally we’d like to be able to tell which job is currently running. For example, in this scenario:

- command: "tests.sh"
  concurrency: 5
  concurrency_group: "tests"

I would like the running build to know which number job it is out of the 5 possible jobs.

This functionality already exists more or less exactly as I would like it in the parallelism feature - you get two env vars that give you the number of total parallel jobs and which one of those jobs is represented by the current build:

BUILDKITE_PARALLEL_JOB=0
BUILDKITE_PARALLEL_JOB_COUNT=5

Is this possible and I’m not seeing it, or is this something we can get simply another way?

Hi @SeanR! Concurrency groups don’t have a start and end counter, like parallelism does. So I’m scratching my head to figure out how you’d get those sort of environment variables working :thinking:

This sounds sort of like a job for agent queues than the concurrency group perhaps, but it’s hard to know exactly.

With agent queues, and using a fixed number of agents, you can more easily tell which agents are busy with which jobs. But you won’t get that sort of info as environment variables like you showed.

Is there a way for the shared set of resources to tell the job above which one they are? What type of resources? If we have a little bit more info about the underlying problem you’re solving, maybe we can suggest alternative ideas.