Detailed CICD (13) - Sonar code scanning

Today, I will continue to introduce Linux operation and maintenance related knowledge. The main content of this article is Sonar code scanning.

1. Sonar Scanner installation

Sonar Scanner can be downloaded from Sonarqube's official website. The download address is: https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/ , the page is as follows:
insert image description here
After the download is complete, we will unzip it and put it in / usr/local/sonarscanner/ directory.

2. Download the test code

After that, let's download the test code. Sonar's test code can be downloaded on Github and searched directly on Github. The result is as follows:
insert image description here
We download the appropriate Sonar code and unzip it to /usr/local/sonar- exp/ directory.

3. Code scanning

After that, we configure Sonar Scanner, open Sonar Scanner's configuration file /usr/local/sonarscanner/conf/soner-scanner.properties, and write the following content to the configuration file:

sonar.host.url=http://localhost:9000
sonar.sourceEncoding=UTF-8
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
sonar.projectKey=exp
sonar.projectName=exp_sonar
sonar.projectVersion=1.0.0
sonar.sources=/usr/local/sonar-exp/projects/java-runner/src

In the above configuration, sonar.jdbc.username and sonar.jdbc.password represent Sonar's database username and password, sonar.host.url represents Sonar's listening address and port number, sonar.sourceEncoding represents Sonar's encoding method, sonar.jdbc .url represents the link method of the database, here our content comes from Sonar's configuration file. sonar.projectKey is the keyword of the Sonar Scanner customized by us, sonar.projectName is the name of the scanning project, sonar.projectVersion is the version of the Sonar project, and sonar.sources is the project directory to be scanned.
The configured file looks like this:
insert image description here
After that, we execute the command:

/usr/local/sonarscanner/bin/sonar-scanner

The execution result is as follows:
insert image description here

Fourth, the effect test

Finally, let's check the results of the configuration just now, revisit the Sonar page, and find that the exp_sonar project appears, as shown below:
insert image description here
We can click to enter the project to view, and the results are as follows:
insert image description here
So far, our Sonar code scanning is successful!
Originality is not easy, please indicate the source for reprinting: https://blog.csdn.net/weixin_40228200

おすすめ

転載: blog.csdn.net/weixin_40228200/article/details/123884233