String msg = String.format( "Invalid data, null schedule for builddef id=%s/project id=%s",
buildDef.getId(), firstBuildableProject.getId() );
log.error( msg );
throw new BuildManagerException( msg + ", please notify your system adminitrator" );
}
OverallBuildQueue overallBuildQueue = getOverallBuildQueueWhereProjectsInGroupAreQueued( projectGroupId );
if ( overallBuildQueue == null )
{
overallBuildQueue = getOverallBuildQueue( BUILD_QUEUE, buildDef.getSchedule().getBuildQueues() );
}
if ( overallBuildQueue != null )
{
for ( Project project : projects )
{
try
{
if ( isInQueue( project.getId(), BUILD_QUEUE, projectsBuildDefinitionsMap.get(
project.getId() ).getId() ) )
{
log.warn( "Project '" + project.getId() + "' - '" + project.getName() +
"' is already in build queue." );
continue;
}
else if ( isProjectInAnyCurrentBuild( project.getId() ) )
{
log.warn( "Project '" + project.getId() + "' - '" + project.getName() +
"' is already building." );
continue;
}
}
catch ( TaskQueueException e )
{
log.warn( "Error occurred while verifying if project is already queued." );
continue;
}
BuildDefinition buildDefinition = projectsBuildDefinitionsMap.get( project.getId() );
String buildDefinitionLabel = buildDefinition.getDescription();
if ( StringUtils.isEmpty( buildDefinitionLabel ) )
{
buildDefinitionLabel = buildDefinition.getGoals();
}
ScmResult scmResult = scmResultMap.get( project.getId() );
BuildProjectTask buildTask = new BuildProjectTask( project.getId(), buildDefinition.getId(),
buildTrigger, project.getName(),
buildDefinitionLabel, scmResult,
projectGroupId );
if ( buildDefinition.getSchedule() == null )
{
log.warn( String.format( "Invalid data, null schedule for builddef id=%s/project id=%s",
buildDef.getId(), project.getId() ) );
}
else
{
buildTask.setMaxExecutionTime( buildDefinition.getSchedule().getMaxJobExecutionTime() * 1000 );
}
try
{
log.info( "Project '" + project.getId() + "' - '" + project.getName() +
"' added to overall build queue '" + overallBuildQueue.getName() + "'." );
overallBuildQueue.addToBuildQueue( buildTask );
}
catch ( TaskQueueException e )
{
throw new BuildManagerException(
"Error occurred while adding project to build queue: " + e.getMessage() );