用于 jenkins 的 SonarQube 扫描器的分析参数如何与 maven 一起工作?

How does the analyse paramethers for SonarQube scanner for jenkins with maven works?

你好我正在尝试使用此处描述的方法使用 Jenkins 的 sonarQube 扫描仪分析 java maven 项目:SonarQube Scanner Documentation,现在在 使用 SonarQube 扫描仪分析部分对于 Maven,它说创建 Jenkins maven 作业你只需要添加到目标中:$SONAR_MAVEN_GOAL -Dsonar.host.url=$SONAR_HOST_URL

看起来像这样:Build Image

现在我这样做了,在构建环境部分单击准备sonarQube扫描仪环境旁边的蓝色问号后,您还可以找到更多这些环境变量。

它工作并分析了我在 Source Code Management 的源代码管理中指定的一个 gitlab 存储库。

但是,当我尝试将其更改为另一个存储库时,首先它只是分析了我之前指定的同一个存储库,它 运行 对旧存储库进行了分析,还发送了旧存储库的结果对于我的 SonarQube 服务器,它完全忽略了我在源代码管理部分指定了不同的 gitlab 存储库。

后来,我尝试向 maven 目标添加全新安装选项,它在构建输出控制台的末尾抛出错误:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar (default-cli) on project Export: Please provide compiled classes of your project with sonar.java.binaries property -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

所以这让我想到了我认为我在配置环境变量方面做错了什么,我不明白 $SONAR_MAVEN_GOAL -[=32= 的实际值是多少]=$SONAR_HOST_URL 或任何其他环境变量。

我的最终目标是能够使用来自 Jenkins 的 java maven 项目分析 Gitlab 存储库。

您可以在使用标准 Jenkins 构建步骤构建项目后触发 SonarQube 分析,请参阅Analyzing with SonarQube Scanner for Jenkins

Features

This plugin lets you centralize the configuration of SonarQube server connection details in Jenkins global configuration.

Then you can trigger SonarQube analysis from Jenkins using standard Jenkins Build Steps to trigger analysis with:

  • SonarQube Scanner
  • SonarQube Scanner for Maven
  • SonarQube Scanner for MSBuild

或使用 Post-build 操作,请参阅 Analyzing with SonarQube Scanner for Maven:

The Post-build Action for Maven analysis is still available, but is deprecated.

使用 Freestyle 项目,您可以为 SonarQube 分析添加构建步骤,例如:

使用 Maven 项目 (Maven Integration) 您可以为 SonarQube 分析添加一个 Post-build 操作,例如: