Jenkins集成Allure插件执行TestNG测试部分用例丢失求助
I’ve run into similar headaches with parallel TestNG tests and the Jenkins Allure plugin before—here are the most actionable fixes to try:
1. Check Version Compatibility
First, make sure your Allure toolchain versions are aligned:
- Update the Allure Jenkins plugin to the latest stable release (older versions have known bugs with parallel test result aggregation).
- Ensure your project’s
allure-testngdependency version matches (or is compatible with) the Jenkins plugin version. Mismatched versions often lead to unparsable result files that the plugin ignores.
2. Fix Parallel Result File Conflicts
Your TestNG config uses parallel="methods" across two browser-specific <test> blocks—this means multiple threads are writing to the default target/allure-results directory simultaneously, causing file overwrites or incomplete data.
Solution: Split Result Directories
Configure each <test> block to generate results in a unique folder, then tell Jenkins to aggregate all of them:
- For Maven projects, update the
maven-surefire-pluginto pass a dynamic results directory using the test name:<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.1.2</version> <configuration> <suiteXmlFiles> <suiteXmlFile>testng.xml</suiteXmlFile> </suiteXmlFiles> <systemPropertyVariables> <allure.results.directory>target/allure-results-${test.name}</allure.results.directory> </systemPropertyVariables> </configuration> </plugin> - In your Jenkins job’s Allure plugin settings, set the Results directory to
target/allure-results-*(this will pick up all browser-specific result folders).
3. Clean Up Jenkins Workspace
Leftover files from previous builds can interfere with result aggregation:
- Add a pre-build step to clean your project (e.g., run
mvn cleanfor Maven projects) to ensure thetargetdirectory is empty before testing starts. - Verify the Jenkins user has write permissions to the workspace directory—missing permissions can prevent some result files from being saved entirely.
4. Debug with Jenkins Build Logs
Dig into your Jenkins build’s console output for Allure-related warnings or errors:
- You might see messages like "Failed to parse result file" or "Missing test result entry" which will pinpoint exactly which test cases or files are causing issues.
- This is the fastest way to tell if the problem is with result generation or plugin aggregation.
5. Adjust Parallel Execution Strategy
If method-level parallelism is causing too much concurrency for Allure’s TestNG adapter, try temporarily switching your parallel value to tests or classes in your TestNG XML:
<suite name="All in one" verbose="1" thread-count="2" parallel="tests" >
If this fixes the missing test cases, the issue likely stems from how the Allure adapter handles method-level parallel writes. You can either stick with a less granular parallel strategy or upgrade to the latest allure-testng version to see if the bug is resolved.
内容的提问来源于stack exchange,提问作者Martin Keprta

