Table of contents
1. Install and deploy sonarqube7.8+postgres13.4
2. Initialize the sonar project
Purpose: After jenkins updates the project, it automatically calls the sonar task to automatically update the sonar every time the project is updated
1. Install and deploy sonarqube7.8+postgres13.4
pull image
docker pull postgres:13.4
docker pull sonarqube:7.8-community
Create a custom network
docker network create sonar-postgres
Create a mount directory
mkdir -p /home/sonar/postgres/postgresql
mkdir -p /home/sonar/postgres/data
mkdir -p /data/sonarqube
Modify system parameters
echo "vm.max_map_count=262144" > /etc/sysctl.conf
sysctl -p
enable container
docker run --name postgres -d -p 5432:5432 --net sonar-postgres \
-v /home/sonar/postgres/postgresql:/var/lib/postgresql \
-v /home/sonar/postgres/data:/var/lib/postgresql/data \
-v /etc/localtime:/etc/localtime:ro \
-e POSTGRES_USER=sonar \
-e POSTGRES_PASSWORD=sonar \
-e POSTGRES_DB=sonar \
-e TZ=Asia/Shanghai \
--restart always \
--privileged=true \
--network-alias postgres \
postgres:13.4
Create a test container and copy the sonar file to the mount directory
docker run -d --name sonartest sonarqube:7.8-community
docker cp sonartest:/opt/sonarqube/conf /data/sonarqube
docker cp sonartest:/opt/sonarqube/extensions /data/sonarqube
chmod -R 777 /data/sonarqube/
docker stop sonartest
docker rm sonartest
Create a sonar container
docker run -d --name sonar -p 9090:9000 \
-e ALLOW_EMPTY_PASSWORD=yes \
-e SONARQUBE_DATABASE_USER=sonar \
-e SONAR_JDBC_USERNAME=sonar \
-e SONAR_JDBC_PASSWORD=sonar \
-e SONARQUBE_JDBC_URL="jdbc:postgresql://postgres:5432/sonar" \
--net sonar-postgres \
--privileged=true \
--restart always \
-v /data/sonarqube/logs:/opt/sonarqube/logs \
-v /data/sonarqube/conf:/opt/sonarqube/conf \
-v /data/sonarqube/data:/opt/sonarqube/data \
-v /data/sonarqube/extensions:/opt/sonarqube/extensions\
sonarqube:7.8-community
Open the website ip+9090 configuration project user name password default admin
Install the Chinese language pack
https://github.com/xuhuisheng/sonar-l10n-zh/releases/tag/sonar-l10n-zh-plugin-1.28
download jar
cp sonar-l10n-zh-plugin-1.28.jar /data/sonarqube/extensions/plugins
Restart the sonar container
Log in to create a project and select maven
2. Initialize the sonar project
Log in to create a project and select maven
Execute the copied command in the root directory of the maven project to execute sonar (copy and store a copy of this command for later use)
mvn sonar:sonar \
-Dsonar.projectKey=xxx \
-Dsonar.host.url=xxx \
-Dsonar.login=xxx
Wait for a while and you will see the test results
3. Integrate jenkins
Create a freestyle jenkins project
Write git address in source control
Add a build step to the build environment -> Execute shell
This script is the script just executed in the project directory
After the build is successful, this task can be added to the task of the post-build operation of the project to update the project and update the sonar