How can I dynamically assign agents?


I have several projects with this basic build chain. 1. Setup Host. 2. Run Program. 3. Analyze program logs. I need to have these steps separated into different jobs, and each job in a specific build chain needs to run on the same host. Analyze always needs to run immediately after it's run dependency, and Run always needs to run immediately after its setup dependency. I've noticed that if two different projects run at the same time on the same hardware results get ruined. Also each project has several build dependencies.

My current solution is to assign specific agents to each job. But that's not an efficient use of our agents. How can I dynamically assign agents to a job? It would be nice if I could place a lock on an agent at the setup step, and release it on the analyze step.

I noticed that there are build priorities I could test out. But it looks like those can be overridden by the queue algorithm.

Comment actions Permalink

Hi - so I assume you have configured this build chain in TeamCity as a set of dependencies? If you have used the 'Snapshot dependency' way to configure your builds then there's the option when you 'Add new snapshot dependency' -> ' Run build on the same agent'.

Comment actions Permalink

Ok, cool. I didn't realize that option was there. That will be useful.

But how can I guarantee build order? For instance lets say I have these two chains and I queue up multiple chains.
build_chain1: setup1->run1->analyze1

build_chain2: setup2>run2->analyze2

How can I guarantee setup1/run1/or analyze1 will never run in between setup2/run2 or run2/analyze2

Comment actions Permalink

Assuming you set up your build chain as snapshot dependencies, when you run the 'Analyse' build TeamCity will submit setup1 to run first, then run1 and then analyze.

However I don't know if this means they're treated as the same priority and get queued one after the other, or if you have multiple builds waiting it will schedule them in between your build steps.

I don't really think TeamCity works that way, you may find some inspiration from this post which is about using the agent requirement feature which lets you run your build on a specific agent, you might find a crafty way to set up your requirements in a way that they exclude builds from running on an agent while it's running another build chain.


Please sign in to leave a comment.