}
}
log.debug( "Determining which build agent should build the project..." );
OverallDistributedBuildQueue overallDistributedBuildQueue = getOverallDistributedBuildQueueByGroup(
projectGroupId, scmRoots, scmRootId );
if ( overallDistributedBuildQueue == null )
{
log.debug(
"No projects with the same continuum group is currently building, checking if build definition has an attached build agent group" );
if ( hasBuildagentGroup( projectsBuildDefinitionsMap ) )
{
log.debug(
"Build definition used has an attached build agent group, checking if there are configured build agents in the group" );
if ( !hasBuildagentInGroup( projectsBuildDefinitionsMap ) )
{
log.warn( "No build agent configured in build agent group. Not building projects." );
throw new NoBuildAgentInGroupException( "No build agent configured in build agent group" );
}
else
{
// get overall distributed build queue from build agent group
log.info( "Getting the least busy build agent within the build agent group" );
overallDistributedBuildQueue = getOverallDistributedBuildQueueByAgentGroup(
projectsBuildDefinitionsMap );
}
}
else
{
// project does not have build agent group
log.info( "Project does not have a build agent group, getting the least busy of all build agents" );
overallDistributedBuildQueue = getOverallDistributedBuildQueue();
}
}
if ( overallDistributedBuildQueue != null )
{
try
{
String agentUrl = overallDistributedBuildQueue.getBuildAgentUrl();
log.info( "Building project in the least busy agent {}", agentUrl );
overallDistributedBuildQueue.addToDistributedBuildQueue( task );
createProjectRunSummaries( task, agentUrl );
}
catch ( TaskQueueException e )
{
log.error( "Error while enqueuing prepare build task", e );