【问题标题】:Why Jenkins job for maven project throws error after specifying maven goals to trigger SonarQube analysis为什么 Maven 项目的 Jenkins 工作在指定 Maven 目标以触发 SonarQube 分析后抛出错误
【发布时间】:2018-07-08 02:08:44
【问题描述】:

我正在尝试运行 Jenkins 作业,该作业应该分析使用 gitlab 源管理的 maven 构建的 java 项目,使用 maven 的 sonarqube 扫描仪...当我进入该作业的目标时,生成的确切内容使用 SonarQube 服务器创建令牌教程,如下所示:

mvn sonar:sonar \
  -Dsonar.host.url=http://***** \
  -Dsonar.login=****

它给我抛出了这种错误:

[ERROR] Unknown lifecycle phase "mvn". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [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.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException

我不知道在詹金斯工作中我的目标中缺少什么或者我应该添加什么,谢谢。

我的 maven 项目配置的屏幕截图:

【问题讨论】:

  • 您是否在 Jenkins 中使用 Maven 构建步骤?如果是这样,它会为您提供初始的mvn,因此您的实际输出是mvn mvn sonar:sonar...
  • 通过 Maven 构建步骤,您的意思是如果我使用的是 Maven 项目?我已将构建作业配置屏幕添加到帖子中。
  • 所以我大概想通了。

标签: maven jenkins sonarqube


【解决方案1】:

在 Jenkins 中,您无需在目标执行中提供 mvn。

通过在顶级 maven 任务中删除 mvn 来尝试 sonar:sonar \ -Dsonar.host.url=http://***** \ -Dsonar.login=****。

【讨论】:

    【解决方案2】:

    所以我最终想通了,总结一下。

    您需要让给定项目成为 Jenkins 中的 Maven 项目。

    您当然需要在 SonarQube 服务器和 Jenkins 中正确配置和集成所有内容,但这就是这个问题的意义所在。

    然后您将只添加环境变量到构建步骤,例如

    $SONAR_MAVEN_GOAL -Dsonar.host.url=$SONAR_HOST_URL
    

    如给定documentation中所述

    最重要的是在jenkins中有一个maven项目。我之前尝试过这个变体,但它不起作用,因为它不是 jenkins 中的 maven 项目,而是 freestyle 项目。

    构建配置截图示例:

    CorrectBuildConfig

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-13
      • 1970-01-01
      • 2012-05-01
      • 2016-01-12
      • 1970-01-01
      • 1970-01-01
      • 2018-12-01
      • 1970-01-01
      相关资源
      最近更新 更多