能否重新推送SonarQube分析结果至服务器?避免重跑2小时分析
Got it, let's cut straight to the chase—you don't need to re-run that 2-hour analysis just to resubmit the results. Here's how to reuse the already-generated local report:
Step 1: Locate the Local Analysis Report
When SonarScanner finishes a successful analysis, it stores the report file locally, usually in the .scannerwork directory of your project. To find the exact path:
- Open the file
.scannerwork/report-task.txt(this is generated automatically after analysis) - Look for the
reportPathline—it will point to the actual report file (typically namedsonar-report.json)
Step 2: Resubmit the Report Using SonarScanner
Use the sonar-scanner command with parameters to skip analysis and send the existing report directly to your server. Replace the placeholders with your project details:
sonar-scanner \ -Dsonar.skipAnalysis=true \ -Dsonar.report.path=/full/path/to/your/sonar-report.json \ -Dsonar.projectKey=your-project-key \ -Dsonar.host.url=http://your-sonar-server-url \ -Dsonar.login=your-auth-token-or-username:password
Breakdown of Key Parameters:
sonar.skipAnalysis=true: Tells SonarScanner to skip running the code analysis entirely and just focus on sending the report.sonar.report.path: Absolute path to the local report file you found in Step 1.- The other parameters (
projectKey,host.url,login) should match exactly what you used for the original analysis.
Pro Tip for Future Runs
To avoid this hassle next time, add the following parameter to your original analysis command to export a copy of the report to a location you can easily access:
-Dsonar.report.export.path=./sonar-report-backup.json
This saves a standalone copy of the report outside the .scannerwork directory (which might get cleaned up by build tools).
Notes to Keep in Mind
- Make sure the report file is compatible with your SonarQube server version (since you're using 6.7.2 LTS for both, this won't be an issue).
- Your authentication credentials need to have permission to submit analysis results for the target project.
Give this a try—you’ll save that 2-hour wait in no time!
内容的提问来源于stack exchange,提问作者pavan krishna

