Skip to content

Commit

Permalink
Integrated code lifecycle: Fix an issue with stale containers (#10005)
Browse files Browse the repository at this point in the history
  • Loading branch information
BBesrour authored Dec 12, 2024
1 parent e687499 commit cc6c76d
Showing 1 changed file with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,16 @@ private BuildResult runScriptAndParseResults(BuildJobQueueItem buildJob, String
buildLogsMap.appendBuildLogEntry(buildJob.id(), msg);
log.info(msg);

TarArchiveInputStream testResultsTarInputStream;
TarArchiveInputStream testResultsTarInputStream = null;

BuildResult buildResult;

try {
testResultsTarInputStream = buildJobContainerService.getArchiveFromContainer(containerId, LOCALCI_WORKING_DIRECTORY + LOCALCI_RESULTS_DIRECTORY);

buildResult = parseTestResults(testResultsTarInputStream, buildJob.buildConfig().branch(), assignmentRepoCommitHash, testRepoCommitHash, buildCompletedDate,
buildJob.id());
buildResult.setBuildLogEntries(buildLogsMap.getAndTruncateBuildLogs(buildJob.id()));
}
catch (NotFoundException e) {
msg = "Could not find test results in container " + containerName;
Expand All @@ -332,7 +338,22 @@ private BuildResult runScriptAndParseResults(BuildJobQueueItem buildJob, String
// If the test results are not found, this means that something went wrong during the build and testing of the submission.
return constructFailedBuildResult(buildJob.buildConfig().branch(), assignmentRepoCommitHash, testRepoCommitHash, buildCompletedDate);
}
catch (IOException | IllegalStateException e) {
msg = "Error while parsing test results";
buildLogsMap.appendBuildLogEntry(buildJob.id(), msg);
throw new LocalCIException(msg, e);
}
finally {
try {
if (testResultsTarInputStream != null) {
testResultsTarInputStream.close();
}
}
catch (IOException e) {
msg = "Could not close test results tar input stream";
buildLogsMap.appendBuildLogEntry(buildJob.id(), msg);
log.error(msg, e);
}
buildJobContainerService.stopContainer(containerName);

// Delete the cloned repositories
Expand All @@ -357,22 +378,6 @@ private BuildResult runScriptAndParseResults(BuildJobQueueItem buildJob, String
}
}

msg = "~~~~~~~~~~~~~~~~~~~~ Parsing test results for build job " + buildJob.id() + " ~~~~~~~~~~~~~~~~~~~~";
buildLogsMap.appendBuildLogEntry(buildJob.id(), msg);
log.info(msg);

BuildResult buildResult;
try {
buildResult = parseTestResults(testResultsTarInputStream, buildJob.buildConfig().branch(), assignmentRepoCommitHash, testRepoCommitHash, buildCompletedDate,
buildJob.id());
buildResult.setBuildLogEntries(buildLogsMap.getAndTruncateBuildLogs(buildJob.id()));
}
catch (IOException | IllegalStateException e) {
msg = "Error while parsing test results";
buildLogsMap.appendBuildLogEntry(buildJob.id(), msg);
throw new LocalCIException(msg, e);
}

msg = "Building and testing submission for repository " + assignmentRepositoryUri.repositorySlug() + " and commit hash " + assignmentRepoCommitHash + " took "
+ TimeLogUtil.formatDurationFrom(timeNanoStart) + " for build job " + buildJob.id();
buildLogsMap.appendBuildLogEntry(buildJob.id(), msg);
Expand Down

0 comments on commit cc6c76d

Please sign in to comment.