如何修改Allure报告中的Suite名称以解决Jenkins并行测试时的报告覆盖问题
Hey there! I totally get your frustration with parallel test runs overwriting each other's Allure reports. Let's break down how to set dynamic Suite names and ensure your Jenkins parallel jobs don't clobber results.
1. Dynamic Suite Name with Allure Lifecycle API
You're already on the right track with updating test case names—modifying the Suite name uses a similar approach, but we'll target the suite label in the test result.
Add this code in a setup method (like @BeforeClass if you want the Suite name applied to all tests in the class, or @BeforeMethod for per-method control) to set a custom Suite name based on your input variable (e.g., customer):
import io.qameta.allure.Allure; import io.qameta.allure.model.Label; // Inside your test setup logic String customSuiteName = "Account Creation - " + customer; // Use your input variable here Allure.getLifecycle().updateTestCase(testResult -> { // Remove existing suite labels to avoid duplicates testResult.getLabels().removeIf(label -> "suite".equals(label.getName())); // Add the new dynamic suite label testResult.getLabels().add(new Label().setName("suite").setValue(customSuiteName)); });
This will ensure each parallel run's tests are grouped under a unique Suite name in the Allure report.
2. Avoid Report Overwrites in Jenkins
Even with unique Suite names, if all parallel jobs write to the same allure-results directory, they'll still overwrite each other. Fix this by assigning a unique results directory per parallel branch in your Jenkinsfile:
pipeline { agent any stages { stage('Parallel Tests') { steps { parallel { 'Customer Alpha' { sh './gradlew test -Dcustomer=Alpha -Dallure.results.directory=allure-results-alpha' } 'Customer Beta' { sh './gradlew test -Dcustomer=Beta -Dallure.results.directory=allure-results-beta' } // Add more parallel branches as needed } } } stage('Generate Allure Report') { steps { allure( results: [ [path: 'allure-results-alpha'], [path: 'allure-results-beta'] // Include all unique result directories here ], reportBuildPolicy: 'ALWAYS' ) } } } }
By specifying a unique allure.results.directory for each run and then telling the Allure Jenkins plugin to collect results from all these directories, you'll preserve all test results and see them grouped by your custom Suite names.
Bonus: Verify the Setup
After running the pipeline, check the Allure report—you should see separate Suites for each customer, with all their corresponding test methods intact, no overwrites!
内容的提问来源于stack exchange,提问作者stru4OK

