Use agent only if build was triggered via REST api

Hi all,
i'm using the TeamCity version: 2017.1.3 (build 46961).
I have the following usecase:

I have three agents and multiple build configurations. I want that my third agent (agent03) is only used if a build is triggered via REST api.

Is that possible?
Thank you
Regards Patrick

0
2 comments
Hello Patrick,
It would be possible to do using agent requirements:
  1. Set an agent requirement in the build templates/build configurations so that the agents used by default would be different than your Agent03 (as an example, teamcity.agent.name does not equal Agent03);
  2. Before triggering the Build via REST API override (via the REST API also) the agent requirement so that the intended agent can run the build. You can find more information about it here:
  3. You run the build specifying the agent via REST API using the <agent id="agentId"/> element.
  4. You set the agent requirement back to the original value defined in 1.
Please read the following post, it has useful information on how to change agent requirements via the Rest API.
 
If in the scenario you have in mind it is not required that the agent is only added "as a possible agent" when using rest while preferring the others (as covered in the solution above) and you just want to force the build to run on agent 3, you can do it through a REST call. That way, once the build is added to the queue, it will be restricted to that agent, so it will wait until the agent is free if needed (and if other builds are in front of the queue and can run there will also have to wait for those). 
 
Please let me know if this solution works for you.
 
Thank you,
1

Guilherme Barbosa

Hi,
Thank you for your comment. :-)

I have thought about this approach as well, but I was hoping there was a better way to do it.

 

Thank you

Regards Patrick

0

Please sign in to leave a comment.