From 76bd145e1390a7f743b90af9ae66cf501d2f415d Mon Sep 17 00:00:00 2001 From: Liu Han Date: Fri, 15 Dec 2023 19:18:21 +0800 Subject: [PATCH 1/2] fix: Calling allure step multiple times in one build causes errors 1. allure icon in the build history duplicated. 2. Files.move method error: allure-report.zip already exists. --- .../qatools/allure/jenkins/AllureReportPublisher.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/yandex/qatools/allure/jenkins/AllureReportPublisher.java b/src/main/java/ru/yandex/qatools/allure/jenkins/AllureReportPublisher.java index 8f86343..46f7539 100644 --- a/src/main/java/ru/yandex/qatools/allure/jenkins/AllureReportPublisher.java +++ b/src/main/java/ru/yandex/qatools/allure/jenkins/AllureReportPublisher.java @@ -363,7 +363,9 @@ private void generateReport(final @Nonnull List resultsPaths, final AllureReportBuildAction buildAction = new AllureReportBuildAction( FilePathUtils.extractSummary(run, reportPath.getName())); buildAction.setReportPath(reportPath); - run.addAction(buildAction); + // run.addAction(buildAction); + // change to below. Calling allure multiple times would produce many allure icons + run.addOrReplaceAction(buildAction); run.setResult(buildAction.getBuildSummary().getResult()); } @@ -383,7 +385,10 @@ private void saveAllureArtifact(final Run run, Objects.requireNonNull(reportPath.getParent()) .archive(TrueZipArchiver.FACTORY, os, reportPath.getName() + "/**"); } - + if (archive.exists() && !archive.delete()) { + listener.getLogger().println("Artifact already exists but unable to be deleted"); + return; + } Files.move(tempArchive.toPath(), archive.toPath()); listener.getLogger().println("Artifact was added to the build."); } From ae937dbdc516424e2503dd5ff542d4e0851ac92b Mon Sep 17 00:00:00 2001 From: Liu Han Date: Thu, 21 Dec 2023 14:39:12 +0800 Subject: [PATCH 2/2] fix: Figure of current build appears multiple times in trend not count current build into history. --- .../ru/yandex/qatools/allure/jenkins/utils/FilePathUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ru/yandex/qatools/allure/jenkins/utils/FilePathUtils.java b/src/main/java/ru/yandex/qatools/allure/jenkins/utils/FilePathUtils.java index f4bc732..34abee5 100644 --- a/src/main/java/ru/yandex/qatools/allure/jenkins/utils/FilePathUtils.java +++ b/src/main/java/ru/yandex/qatools/allure/jenkins/utils/FilePathUtils.java @@ -83,7 +83,7 @@ public static void deleteRecursive(final FilePath filePath, public static FilePath getPreviousReportWithHistory(final Run run, final String reportPath) throws IOException, InterruptedException { - Run current = run; + Run current = run.getPreviousCompletedBuild(); while (current != null) { final FilePath previousReport = new FilePath(current.getArtifactsDir()).child(ALLURE_REPORT_ZIP); if (previousReport.exists() && isHistoryNotEmpty(previousReport, reportPath)) {