1、部署jenkins(本文不做说明)
2、部署sonarqube(docker-compose)
version: "2.1"
services:
sonarqube:
image: sonarqube:9.9.4-community
container_name: sonarqube
depends_on:
- db
ports:
- 9000:9000
networks:
- sonarnet
environment:
SONARQUBE_JDBC_URL: jdbc:postgresql://db:5432/sonar
SONARQUBE_JDBC_USERNAME: sonar
SONARQUBE_JDBC_PASSWORD: sonar
volumes:
- ./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.jar
db:
image: postgres
container_name: postgres
networks:
- sonarnet
environment:
POSTGRES_USER: sonar
POSTGRES_PASSWORD: sonar
POSTGRES_DB: sonar
volumes:
- ./postgresql:/var/lib/postgresql
- ./postgresql/data:/var/lib/postgresql/data
networks:
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