build-coordinator/src/main/java/org/jboss/pnc/coordinator/builder/datastore/DatastoreAdapter.java
public BuildRecord storeResult(BuildTask buildTask, Optional<BuildResult> buildResult, Throwable e) throws DatastoreException {
        BuildRecord.Builder buildRecordBuilder = initBuildRecordBuilder(buildTask);
        buildRecordBuilder.status(SYSTEM_ERROR);

        StringBuilder errorLog = new StringBuilder();

        buildResult.ifPresent(result -> {

            result.getRepourResult().ifPresent(repourResult -> {
                buildRecordBuilder.executionRootName(repourResult.getExecutionRootName());
                buildRecordBuilder.executionRootVersion(repourResult.getExecutionRootVersion());
                buildRecordBuilder.repourLog(repourResult.getLog());
            });

            result.getBuildDriverResult().ifPresent(
                buildDriverResult -> {
                    errorLog.append(buildDriverResult.getBuildLog());
                    errorLog.append("\n---- End Build Log ----\n");
            });

            result.getRepositoryManagerResult().ifPresent(
                rmr -> {
                    errorLog.append(rmr.getLog());
                    errorLog.append("\n---- End Repository Manager Log ----\n");
            });

            result.getEnvironmentDriverResult().ifPresent(
                r -> {
                    if (r.getLog() != null && !r.getLog().equals(""))
                    errorLog.append(r.getLog());
                    errorLog.append("\n---- End Environment Driver Log ----\n");
            });
        });

        errorLog.append("Build status: ").append(getBuildStatus(buildResult)).append("\n");
        errorLog.append("Caught exception: ").append(e.toString()).append("\n");
        StringWriter stackTraceWriter = new StringWriter();
        e.printStackTrace(new PrintWriter(stackTraceWriter));
        errorLog.append(stackTraceWriter.getBuffer());
        buildRecordBuilder.buildLog(errorLog.toString());

        userLog.error("Build status: {}.", getBuildStatus(buildResult));
        log.debug("Storing ERROR result of buildTask.getBuildConfigurationAudited().getName() to datastore.",  e);
        return datastore.storeCompletedBuild(buildRecordBuilder);
    }
public BuildRecord storeResult(BuildTask buildTask, Optional<BuildResult> buildResult, Throwable e) throws DatastoreException {
        BuildRecord.Builder buildRecordBuilder = initBuildRecordBuilder(buildTask);
        buildRecordBuilder.status(SYSTEM_ERROR);

        StringBuilder errorLog = new StringBuilder();

        buildResult.ifPresent(result -> {

            result.getRepourResult().ifPresent(repourResult -> {
                buildRecordBuilder.executionRootName(repourResult.getExecutionRootName());
                buildRecordBuilder.executionRootVersion(repourResult.getExecutionRootVersion());
                buildRecordBuilder.repourLog(repourResult.getLog());
            });

            result.getBuildDriverResult().ifPresent(
                buildDriverResult -> {
                    errorLog.append(buildDriverResult.getBuildLog());
                    errorLog.append("\n---- End Build Log ----\n");
            });

            result.getRepositoryManagerResult().ifPresent(
                rmr -> {
                    errorLog.append(rmr.getLog());
                    errorLog.append("\n---- End Repository Manager Log ----\n");
            });

            result.getEnvironmentDriverResult().ifPresent(
                r -> {
                    if (r.getLog() != null && !r.getLog().equals(""))
                    errorLog.append(r.getLog());
                    errorLog.append("\n---- End Environment Driver Log ----\n");
            });
        });

        errorLog.append("Build status: ").append(getBuildStatus(buildResult)).append("\n");
        errorLog.append("Caught exception: ").append(e.toString()).append("\n");
        StringWriter stackTraceWriter = new StringWriter();
        e.printStackTrace(new PrintWriter(stackTraceWriter));
        errorLog.append(stackTraceWriter.getBuffer());
        buildRecordBuilder.buildLog(errorLog.toString());

        userLog.error("Build status: {}.", getBuildStatus(buildResult));
        log.debug("Storing ERROR result of buildTask.getBuildConfigurationAudited().getName() to datastore.",  e);
        return datastore.storeCompletedBuild(buildRecordBuilder);
    }
Store build result along with error information appended to the build log

@param buildTask task
@param buildResult result of running the task
@param e The error that occurred during the build process
@throws DatastoreException on failure to store data