Pinning all pipeline build steps to the agent on the same machine

Is there a way to pin all steps in BK pipeline to the same agent on the same machine?

BK pipeline uses agents started by AWS CI Stack (which allows to scale agents up and down).

Thanks a lot,

Hi Elena,

That’s a great question! You can make use of queues to accomplish exactly that :slight_smile:. Defining queues and agent tags allows you to control where steps and builds are run. Let me know if that helps or if you have other questions!


Hello Jeremy,

Here is my use case:

  1. I have AWS CI Stack setup with these parameters:
  • Buildkite agent queue = “queue1”
  • Min Size = 1
  • Max Size = 10, which means that AWS autoscaling group will scale up machines depending on how many builds we need to run at the same time up to 10 machines.
  1. Let’s says we have 2 builds (each has 3 steps) running and both of them use agents with queue = “queue1”. AWS Autoscaling Group will start 2 machines: machine1 and machine2. Agents on both machines will have the same queue = “queue1”

  2. Build1 starts running step 1 on machine1.

  3. Build2 starts running step 1 on machine2.

  4. Build1 fails on step 1 so agent on machine2 becomes available.

Actual Result: Build2 step 2 and step 3 end up running on machine 2.

Expected Result: Build2 step 2 and step 3 continue running on machine1 just like step 1.

Hey Elena! :wave:

:thinking: The overall/ideal best practice here is “don’t have a built that relies on multiple steps running on the same agent instance” — beyond limiting possible parallelism, it can also make your build less resilient to an agent machine going away (such that the later job’s one-acceptable-agent is never seen again)
Requiring agent affinity also implies you’ll be working around the default clean-slate behavior between jobs, at which point to potentially need to do more to ensure you do still have a properly cleaned slate between separate builds

However, having said that :sweat_smile:, one option is to stick node affinity to the agent that picks up the initial pipeline upload, such that you can use $BUILDKITE_AGENT_META_DATA_NAME directly to interpolate the currently-running agent’s value into the subsequently-uploaded jobs.
That env var will be interpolated at runtime to the agent’s tag value of “hostname”.
And again, this isn’t recommended :slight_smile: