title: Azure Devops - Get release definitions by agent pool ID
body: <p>I'm trying to find all the builds and releases that are configured to use a specific agent pool, using the .NET Client Libraries.</p>
  
  <p>Assuming <code>agentPoolId</code>, I can get all the build definitions like this:</p>
  
  <pre><code>// _connection is of type VssConnection
  using (var buildClient = _connection.GetClient&lt;BuildHttpClient&gt;())
  {
      List&lt;BuildDefinitionReference&gt; allBuilds = await buildClient.GetDefinitionsAsync(projectName, top: 1000, queryOrder: DefinitionQueryOrder.DefinitionNameAscending);
      List&lt;BuildDefinitionReference&gt; builds = allBuilds.Where(x =&gt; HasAgentPoolId(x, agentPoolId)).ToList();
  }
  
  private bool HasAgentPoolId(BuildDefinitionReference buildDefinition, int agentPoolId)
  {
      TaskAgentPoolReference pool = buildDefinition?.Queue?.Pool;
  
      if (pool == null)
      {
          return false;
      }
  
      return pool.Id.Equals(agentPoolId);
  }
  </code></pre>
  
  <p>But I couldn't find a way to find the release definitions that have one or more environments configured to use a particular agent. Any suggestion?</p>