{
PrepareBuildProjectsTask task = new PrepareBuildProjectsTask( projectsBuildDefinitionsMap, buildTrigger,
projectGroupId, projectGroupName,
scmRootAddress, scmRootId );
OverallDistributedBuildQueue overallDistributedBuildQueue = getOverallDistributedBuildQueueByGroup( projectGroupId, scmRoots, scmRootId );
if ( overallDistributedBuildQueue == null )
{
if ( hasBuildagentGroup( projectsBuildDefinitionsMap ) )
{
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 from 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 build agent" );
overallDistributedBuildQueue = getOverallDistributedBuildQueue();
}
}
if ( overallDistributedBuildQueue != null )
{
try
{
overallDistributedBuildQueue.addToDistributedBuildQueue( task );
}
catch ( TaskQueueException e )
{
log.error( "Error while enqueuing prepare build task", e );
throw new ContinuumException( "Error occurred while enqueuing prepare build task", e );