Sonavcloud与Travis,Maven& github上 [英] Sonarcloud failure with Travis, Maven & github
问题描述
我工作的项目( eclipse / scanning )使用Travis和Sonar进行持续集成和代码分析。
上周,我注意到声纳步骤中的构建失败:
错误:SonarQube扫描程序执行期间出错
org.sonar.squidbridge.api.AnalysisException:请使用sonar.java.binaries属性
提供您的项目的已编译的类
现在,外部的pull请求(来自fork)让它通过在声纳步骤中,集成测试失败的原因不同:
$ mvn -q声纳:声纳
...
[错误]无法到达SonarQube服务器[http:// localhost:9000]
[错误]无法执行目标org.sonarsource.scanner.maven:sonar- maven-plugin:3.3.0.603:项目中的sonar(default-cli)org.eclipse.scanning:无法执行SonarQube:无法从服务器获取引导索引:无法连接到本地主机/ 127.0.0.1:9000:连接被拒绝连接被拒绝) - > [Help 1]
这似乎与日志中较早的差异有关:
出于安全原因,加密的环境变量已被删除。
请参阅https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
以及一个完全缺失的 SonarCloud插件部分。
要查看差异, a href =https://travis-ci.org/eclipse/scanning/builds/262316508 =nofollow noreferrer>失败版本#625 (这是一个来自分叉回购的请求)与成功构建#628 (这是来自回购内部的拉动请求)。
大约一个月前,外部拉动没有问题,例如 build#536 已通过运行
从存储库设置中设置环境变量, SonarCloud addon
和 sonar-scanner
正确。
然而,后续版本,如 build#538 已通过,但只是因为 sonar-scanner
跳过分析,以0
退出,即使它们未能运行。
虽然我可能只是在外部禁用Sonar pull请求,如果我可以修复我们的仓库,这样会很好,所以我们对内部和外部的pull请求都进行了集成测试和代码分析,所以
- 我的原始修补程序是否正确?
- 如果是这样,我如何才能使它同时适用于内部和外部的拉取请求?
- 我应该如何解决原始问题?
请注意,这个问题已被取代,如何让Sonarcloud运行于Travis,Maven& for ; github ,它专注于潜在的问题,而不是试图解决一些症状。
你的PR分析正在尝试(和失败)使用默认服务器:localhost:9000。
在另一种情况下,您可以 update settings.xml 来指定位置,但是由于您使用的是Travis,因此您将在命令行上传递它: mvn sonar:sonar -Dsonar.host.url = https://sonarcloud.io
顺便说一下正在你正常的Travis版本中工作,因为Travis的SonarQube集成专门用于集成Travis- SonarCloud ,所以服务器自动填充。
A project I work on (eclipse/scanning) uses Travis and Sonar for continuous integration and code analysis.
Last week, I noticed that builds were failing at the sonar step with:
ERROR: Error during SonarQube Scanner execution
org.sonar.squidbridge.api.AnalysisException: Please provide compiled classes of your project with sonar.java.binaries property
After some research, I thought I'd fixed this by updating the addons:
section (sonarqube
to sonarcloud
) and switching to using - mvn -q sonar:sonar
rather than - sonar-scanner
in the script:
section of the .travis.yml
file.
Now though, external pull requests (from forks) which make it past the integration tests are failing for a different reason at the sonar step:
$ mvn -q sonar:sonar
...
[ERROR] SonarQube server [http://localhost:9000] can not be reached
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar (default-cli) on project org.eclipse.scanning: Unable to execute SonarQube: Fail to get bootstrap index from server: Failed to connect to localhost/127.0.0.1:9000: Connection refused (Connection refused) -> [Help 1]
This appears to be related to earlier differences in the log:
Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
and an entirely missing SonarCloud addon section.
To see the difference, compare the failed build #625 (which was a pull request from a forked repo) with the successful build #628 (which was a pull request from within the repo).
Around a month ago, external pulls work without issue, for instance build #536 passed, having run Setting environment variables from repository settings
, SonarCloud addon
and sonar-scanner
correctly.
Subsequent builds however, such as build #538 passed, but only because sonar-scanner
skipped analysis and exited with 0
even though they failed to run.
While I could probably just disable Sonar on external pull requests, it would be nice if I could fix our repository so we got both integration tests and code analysis on both internal and external pull requests, so
- Was my original fix the correct one?
- If so, how do I get it to work with both internal and external pull requests?
- If not, how should I have fixed the original problem?
Note, this question has been superceded by How do I get Sonarcloud to run on pull requests from forks with Travis, Maven & github which is focussed on the underlying problem rather than trying to fix some of the symptoms.
Your PR analysis is attempting (and failing) to use the default server: localhost:9000.
In another circumstance, you would update settings.xml to specify the location but since you're using Travis, you'll pass it on the command line instead: mvn sonar:sonar -Dsonar.host.url=https://sonarcloud.io
BTW, this is working in your normal Travis build because the SonarQube integration for Travis is specifically a Travis-SonarCloud integration, so server is filled in automatically.
这篇关于Sonavcloud与Travis,Maven& github上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!