{
// ----------------------------------------------------------------------
// Get parameters from the context
// ----------------------------------------------------------------------
Project project = ContinuumBuildAgentUtil.getProject( context );
BuildDefinition buildDefinition = ContinuumBuildAgentUtil.getBuildDefinition( context );
Map<String, String> environments = ContinuumBuildAgentUtil.getEnvironments( context );
String localRepository = ContinuumBuildAgentUtil.getLocalRepository( context );
int trigger = ContinuumBuildAgentUtil.getTrigger( context );
String username = ContinuumBuildAgentUtil.getUsername( context );
ContinuumAgentBuildExecutor buildExecutor = buildAgentBuildExecutorManager.getBuildExecutor( project.getExecutorId() );
// ----------------------------------------------------------------------
// Make the buildResult
// ----------------------------------------------------------------------
BuildResult buildResult = new BuildResult();
buildResult.setStartTime( new Date().getTime() );
buildResult.setState( ContinuumProjectState.BUILDING );
buildResult.setTrigger( trigger );
buildResult.setUsername( username );
buildResult.setBuildDefinition( buildDefinition );
buildResult.setScmResult( ContinuumBuildAgentUtil.getScmResult( context, null ) );
context.put( ContinuumBuildAgentUtil.KEY_BUILD_RESULT, buildResult );
try
{
File buildOutputFile = buildAgentConfigurationService.getBuildOutputFile( project.getId() );
ContinuumAgentBuildExecutionResult result = buildExecutor.build( project, buildDefinition, buildOutputFile,
environments, localRepository );
buildResult.setState( result.getExitCode() == 0 ? ContinuumProjectState.OK : ContinuumProjectState.FAILED );