1、部署jenkins(本文不做说明)
2、部署sonarqube(docker-compose)
version: "2.1"services:sonarqube:image: sonarqube:9.9.4-communitycontainer_name: sonarqubedepends_on:- dbports:- 9000:9000networks:- sonarnetenvironment:SONARQUBE_JDBC_URL: jdbc:postgresql://db:5432/sonarSONARQUBE_JDBC_USERNAME: sonarSONARQUBE_JDBC_PASSWORD: sonarvolumes:- ./sonarqube/conf:/opt/sonarqube/conf- ./sonarqube/data:/opt/sonarqube/data- ./sonarqube/extensions:/opt/sonarqube/extensions- ./sonarqube/lib/bundled-plugins-plugins:/opt/sonarqube/lib/bundled-plugins- ./sonarqube-community-branch-plugin-1.14.0.jar:/opt/sonarqube/extensions/plugins/sonarqube-community-branch-plugin.jar- ./sonarqube-community-branch-plugin-1.14.0.jar:/opt/sonarqube/lib/common/sonarqube-community-branch-plugin.jardb:image: postgrescontainer_name: postgresnetworks:- sonarnetenvironment:POSTGRES_USER: sonarPOSTGRES_PASSWORD: sonarPOSTGRES_DB: sonarvolumes:- ./postgresql:/var/lib/postgresql- ./postgresql/data:/var/lib/postgresql/datanetworks:sonarnet:driver: bridge
~
sonarqube-community-branch-plugin-1.14.0.jar 地址:https://download.csdn.net/download/weixin_42256094/89340122
3、jenkins 需要用到的配置
SonarQube servers(如图)
SonarQube Scanner(如图)
下载地址:https://download.csdn.net/download/weixin_42256094/89340164
4、项目中调用sonarqube的配置
Analysis properties
sonar.projectKey=guanwang
sonar.projectName=“官网后台”
sonar.projectVersion=1.1.018.000.20201108_beta
#sonar.projectBaseDir=/var/lib/jenkins/workspace/sonar-cscd
sonar.sources=src
sonar.java.binaries=target
sonar.language=java # 项目的语言
sonar.sourceEncoding=UTF-8