持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)

目录

一、实验

1.Java项目扫描

2.视图徽章

3.版本管理


一、实验

1.Java项目扫描

(1)指定项目信息关联的首页为GitLab项目,持续集成为Jenkins流水线

(2)命令行

sonar-scanner -Dsonar.host.url=http://192.168.204.8:9000 \
-Dsonar.projectKey=devops03-maven5-service \
-Dsonar.projectName=devops03-maven5-service \
-Dsonar.projectVersion=1.1 \
-Dsonar.login=admin \
-Dsonar.password=Admin123 \
-Dsonar.ws.timeout=30 \
-Dsonar.projectDescription="my first project" \
-Dsonar.links.homepage=http://192.168.204.8:82/devops03/devops03-maven5-service \
-Dsonar.links.ci=http://192.168.204.15:8080/job/devops03/job/devops03-maven-service/ \
-Dsonar.sources=src \
-Dsonar.sourceEncoding=UTF-8 \
-Dsonar.java.binaries=target/classes \
-Dsonar.java.test.binaries=target/test-classes \
-Dsonar.java.surefire.report=target/surefire-reports

持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第1张图片

(3)扫描过程

INFO: Scanner configuration file: /opt/sonar-scanner-4.8.0.2856-linux/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.8.0.2856
INFO: Java 11.0.17 Eclipse Adoptium (64-bit)
INFO: Linux 3.10.0-693.el7.x86_64 amd64
INFO: User cache: /root/.sonar/cache
INFO: Analyzing on SonarQube server 9.6.1.59531
INFO: Default locale: "zh_CN", source code encoding: "UTF-8"
INFO: Load global settings
INFO: Load global settings (done) | time=439ms
INFO: Server id: 1065B69D-AYwoa-k-vNr7u7v9mI4p
INFO: User cache: /root/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=387ms
INFO: Plugin [l10nzh] defines 'l10nen' as base plugin. This metadata can be removed from manifest of l10n plugins since version 5.2.
INFO: Load/download plugins (done) | time=566ms
INFO: Process project properties
INFO: Process project properties (done) | time=13ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=3ms
INFO: Project key: devops03-maven5-service
INFO: Base dir: /opt/maven-test-master
INFO: Working dir: /opt/maven-test-master/.scannerwork
INFO: Load project settings for component key: 'devops03-maven5-service'
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=754ms
INFO: Load active rules
INFO: Load active rules (done) | time=8729ms
INFO: Load analysis cache
INFO: Load analysis cache (404) | time=328ms
INFO: Load project repositories
INFO: Load project repositories (done) | time=317ms
INFO: Indexing files...
INFO: Project configuration:
INFO: 2 files indexed
INFO: Quality profile for java: Sonar way
INFO: ------------- Run sensors on module devops03-maven5-service
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=358ms
INFO: Sensor JavaSensor [java]
INFO: Configured Java source version (sonar.java.source): none
INFO: JavaClasspath initialization
INFO: JavaClasspath initialization (done) | time=4ms
INFO: JavaTestClasspath initialization
INFO: JavaTestClasspath initialization (done) | time=18ms
INFO: Server-side caching is enabled. The Java analyzer will not try to leverage data from a previous analysis.
INFO: Using ECJ batch to parse 2 Main java source files with batch size 102 KB.
INFO: Starting batch processing.
INFO: The Java analyzer cannot skip unchanged files in this context. A full analysis is performed for all files.
INFO: 100% analyzed
INFO: Batch processing: Done.
INFO: Did not optimize analysis for any files, performed a full analysis for all 2 files.
WARN: Dependencies/libraries were not provided for analysis of SOURCE files. The 'sonar.java.libraries' property is empty. Verify your configuration, as you might end up with less precise results.
WARN: Unresolved imports/types have been detected during analysis. Enable DEBUG mode to see them.
WARN: Use of preview features have been detected during analysis. Enable DEBUG mode to see them.
INFO: No "Test" source files to scan.
INFO: No "Generated" source files to scan.
INFO: Sensor JavaSensor [java] (done) | time=2119ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=4ms
INFO: Sensor CSS Rules [javascript]
INFO: No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
INFO: Sensor CSS Rules [javascript] (done) | time=0ms
INFO: Sensor C# Project Type Information [csharp]
INFO: Sensor C# Project Type Information [csharp] (done) | time=2ms
INFO: Sensor C# Analysis Log [csharp]
INFO: Sensor C# Analysis Log [csharp] (done) | time=26ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=0ms
INFO: Sensor SurefireSensor [java]
INFO: parsing [/opt/maven-test-master/target/surefire-reports]
INFO: Sensor SurefireSensor [java] (done) | time=3ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=4ms
INFO: Sensor Text Sensor [text]
INFO: 2 source files to be analyzed
INFO: 2/2 source files have been analyzed
INFO: Sensor Text Sensor [text] (done) | time=7ms
INFO: Sensor VB.NET Project Type Information [vbnet]
INFO: Sensor VB.NET Project Type Information [vbnet] (done) | time=1ms
INFO: Sensor VB.NET Analysis Log [vbnet]
INFO: Sensor VB.NET Analysis Log [vbnet] (done) | time=24ms
INFO: Sensor VB.NET Properties [vbnet]
INFO: Sensor VB.NET Properties [vbnet] (done) | time=0ms
INFO: ------------- Run sensors on project
INFO: Sensor Analysis Warnings import [csharp]
INFO: Sensor Analysis Warnings import [csharp] (done) | time=1ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=9ms
INFO: Sensor Java CPD Block Indexer
INFO: Sensor Java CPD Block Indexer (done) | time=33ms
INFO: SCM Publisher is disabled
INFO: CPD Executor 1 file had no CPD blocks
INFO: CPD Executor Calculating CPD for 1 file
INFO: CPD Executor CPD calculation finished (done) | time=17ms
INFO: Analysis report generated in 109ms, dir size=125.2 kB
INFO: Analysis report compressed in 32ms, zip size=19.2 kB
INFO: Analysis report uploaded in 534ms
INFO: ANALYSIS SUCCESSFUL, you can find the results at: http://192.168.204.8:9000/dashboard?id=devops03-maven5-service
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://192.168.204.8:9000/api/ce/task?id=AYw3--XiIFiWyj7q-9ox
INFO: Analysis total time: 17.800 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 20.808s
INFO: Final Memory: 19M/70M
INFO: ------------------------------------------------------------------------

持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第2张图片持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第3张图片持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第4张图片

(4)首页多了一个项目

持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第5张图片

(5)点击右上角项目信息-扩展链接-首页

持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第6张图片

(6)会自动跳转GitLab项目

持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第7张图片

(7)点击右上角项目信息-扩展链接-持续集成持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第8张图片

(8)会自动跳转Jenkins流水线

持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第9张图片

2.视图徽章

(1)Sonarqube获取视图徽章

持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第10张图片

(2)复制代码

[![警报](http://192.168.204.8:9000/api/project_badges/measure?project=devops03-maven5-service&metric=alert_status&token=b2c315b631b2780304fab7099f18456f4a514e0c)](http://192.168.204.8:9000/dashboard?id=devops03-maven5-service)

持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第11张图片

(3)会有提示

持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第12张图片

(4)粘贴到GitLab项目的README.md文件

(5)查看效果

(6)添加GitLab本地流水线徽章

[![pipeline status](http://192.168.204.8:82/devops03/devops03-maven5-service/badges/master/pipeline.svg)](http://192.168.204.8:82/devops03/devops03-maven5-service/-/commits/master)

(7)查看效果

(8)整体效果

持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第13张图片

3.版本管理

(1)修改原代码

持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第14张图片

(2)代码扫描,指定版本为1.2

sonar-scanner -Dsonar.host.url=http://192.168.204.8:9000 \
-Dsonar.projectKey=devops03-maven5-service \
-Dsonar.projectName=devops03-maven5-service \
-Dsonar.projectVersion=1.2 \
-Dsonar.login=admin \
-Dsonar.password=Admin123 \
-Dsonar.ws.timeout=30 \
-Dsonar.projectDescription="my first project" \
-Dsonar.links.homepage=http://192.168.204.8:82/devops03/devops03-maven5-service \
-Dsonar.links.ci=http://192.168.204.15:8080/job/devops03/job/devops03-maven-service/ \
-Dsonar.sources=src \
-Dsonar.sourceEncoding=UTF-8 \
-Dsonar.java.binaries=target/classes \
-Dsonar.java.test.binaries=target/test-classes \
-Dsonar.java.surefire.report=target/surefire-reports

持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第15张图片

(3)活动里出现2个版本

持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第16张图片

(4)指定版本分析

持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第17张图片

(5)总览提示新增1行代码

持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第18张图片

(6)会显示具体增加代码的地方

持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第19张图片

(7)具体新增的代码

持续集成交付CICD:Sonarqube 扫描本地项目(关联Gitlab项目与Jenkins流水线)_第20张图片

你可能感兴趣的:(持续集成交付CICD,ci/cd,gitlab,jenkins,运维)