From cc6c76d15e903006e2e175f3fc1326df57b9801d Mon Sep 17 00:00:00 2001 From: Mohamed Bilel Besrour <58034472+BBesrour@users.noreply.github.com> Date: Thu, 12 Dec 2024 08:48:47 +0100 Subject: [PATCH] Integrated code lifecycle: Fix an issue with stale containers (#10005) --- .../service/BuildJobExecutionService.java | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobExecutionService.java b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobExecutionService.java index 2fb2c805bf13..e7fd13c7b97e 100644 --- a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobExecutionService.java +++ b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobExecutionService.java @@ -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; @@ -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 @@ -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);