We have two build agents that runs on the same server serving four projects that are under development as well as under support. 

We want the projects to be build as fast as possible i.e. we don't want to reserv a specific agent for each project since that would likely put some builds in a queue even though another agent is available.

Since we have both unit and integrationstests that targets a databas locally installed on the buildserver we need to have some way of making sure that several checkins for the same project isn't run in parallell on different build agents since that would make collisions in the tests regarding the database.

So how can we setup the build so that a specific project only will trigger a build if no other build for the project currently is running and otherwise place the build in a queue to be started after the previous build for that project is completed?

Some builds take up to an hour to complete so its not really feasible to make the developers remember to trigger a new build.

The following scenario may help to understand the question:

1. Checkin for project A happens which trigger a build on Build agent 1
2. Checkin for project B happens which trigger a build on Build agent 2
3. Another checkin happens for project A which is the put in queue
4. Build of project B completes
5. Second checkin for project A is given to Build agent 2 (triggers collisions in integrationstests)

What we want is instead the following

1. Checkin for project A happens which trigger a build on Build agent 1
2. Checkin for project B happens which trigger a build on Build agent 2
3. Another checkin happens for project A which is the put in queue
4. Build of project B completes
5. Since build is still active for project A the second checkin is not yet started
6. Build of project A completes
7. New build for project A starts on either build agent