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,
Elena

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!

Jeremy

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:

Best!

1 Like

This may be another aspect of pinning a build to an agent. We have an Elastic CI with AWS Linux instances. We’ve created a second Elastic CI with Windows agents to allow for windows builds. When a windows build runs it initially selects the Linux based agent. Thereafter the pipeline.yaml specifies agent: windows and the pipeline stops the current agent and starts the windows agent to complete the build pipeline. How do we specify the windows agent as the starting point of the pipeline without using the pipeline.yml? Is there an environment variable that specifies the agent type?

Hi @tvaillancourt

First of all welcome to Buildkite community and thank you for reaching our to us with your question.

No, in order for having specific pipeline build steps to run on a targeted set of agents you would need to specify the agent targeting rules in your pipeline as explained in Buildkite Agent Job Queues v3 | Buildkite Documentation