Automatically derive mandatory SonarQube properties from pom file in Jenkins

蓝咒 提交于 2019-11-30 12:17:24

The documentation (although slightly confusing, see edit below) explains how to use a generic post-build step (leveraging environment variables), instead of the deprecated post-build action. in short:

  • install latest SonarQube Plugin (v2.4 as of now) in Jenkins
  • in System Config under SonarQube servers: check Enable injection of SonarQube server configuration as build environment variables
  • in the configuration of your Maven project:
    • check Prepare SonarQube Scanner environment
    • add a post-build step Invoke top-level Maven targets and leverage the injected environment variables in the Goals field e.g.:

      $SONAR_MAVEN_GOAL -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_AUTH_TOKEN

Edit: when the documentation says The Post-build Action for Maven analysis is deprecated. , it refers to the old post-build action which is not documented anymore. The paragraph after that warning (summarized in this answer) really is the recommended procedure. Illustration here if it's still not clear.

Using SonarQube Scanner as a post build step you can configure it with at least this properties in Analysis properties:

sonar.projectKey=${POM_ARTIFACTID}
sonar.projectName=${POM_DISPLAYNAME}
sonar.projectVersion=${POM_VERSION}
sonar.sources=src
sonar.java.binaries=target
sonar.language=java
sonar.sourceEncoding=UTF-8

POM_* variables are mapped by Jenkins from Maven GAV info, look here: https://github.com/jenkinsci/jenkins/pull/933/files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!