# Dynamically target agent when creating build

**URL:** <https://forum.buildkite.community/t/dynamically-target-agent-when-creating-build/1034>\
**Category:** General\
**Created:** [May 13, 2020, 12:12am UTC](https://forum.buildkite.community/t/dynamically-target-agent-when-creating-build/1034 "2020-05-13T00:12:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnf](https://avatars.discourse-cdn.com/v4/letter/j/848f3c/32.png) [@johnf](https://forum.buildkite.community/u/johnf)\
**Post date:** [May 13, 2020, 12:12am UTC](https://forum.buildkite.community/t/dynamically-target-agent-when-creating-build/1034/1 "2020-05-13T00:12:56Z")

</div>

When calling a pipeline via the REST API, is it possible to dynamically define the criteria for selecting an agent, rather than having an agent section in the pipeline yaml steps? Put another way, I’d like to be able to define a pipeline that will sometimes run only on an agent that has a metadata attribute “color=blue”. But I’d also sometimes like that **same** pipeline to run only on agents where the color attribute == red (“color=red”.)

I see that I can pass in metadata with a build request. I’d like to be able to pass in blue or red there to define what agents get targeted by the build when a pipeline runs. Is this possible?

Thanks

---

<div class="post-metadata">

**Author:** ![johnf](https://avatars.discourse-cdn.com/v4/letter/j/848f3c/32.png) [@johnf](https://forum.buildkite.community/u/johnf)\
**Post date:** [May 14, 2020, 4:57pm UTC](https://forum.buildkite.community/t/dynamically-target-agent-when-creating-build/1034/2 "2020-05-14T16:57:53Z")

</div>

I’ve kind of sorted this, am just using env vars to configure the agent section of the pipeline.
