DevOps-SonarQube整合Jenkins

news2024/11/19 13:23:47

下载SonarQube Scanner

登录Jenkins服务器,下载SonarQube Scanner

wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip

安装unzip,需要通过它来解压zip压缩包

yum install -y unzip

解压SonarScanner

unzip sonar-scanner-cli-5.0.1.3006-linux.zip

修改目录名称为sonar-scanner

mv sonar-scanner-5.0.1.3006-linux sonar-scanner

修改配置文件

vim sonar-scanner/conf/sonar-scanner.properties 

把注释去掉,修改成你的SonarQube地址

#Configure here general information about the environment, such as SonarQube server connection details for example
#No information about specific project should appear here

#----- Default SonarQube server
sonar.host.url=http://192.168.170.111:9000

#----- Default source code encoding
sonar.sourceEncoding=UTF-8

进入Jenkins数据目录,把sonar-scanner移进来(和JDK、Maven一样)

cd /usr/local/docker/jenkins_docker/data/
mv /root/sonar-scanner ./

在这里插入图片描述

Jenkins配置

进入Dashboard > 系统管理 > 插件管理 > Advanced settings,搜索SonarQube Scanner并安装。
在这里插入图片描述

重启Jenkins生效
在这里插入图片描述

切换到Dashboard > 系统管理 > 全局工具配置 > SonarQube Scanner配置项

网络好可以直接勾选自动安装,我这里前面已经下载解压到Jenkins里面了。

Name好认即可,路径是Jenkins容器内部的路径(和JDK、Maven一样)

在这里插入图片描述

保存后,接着来到Dashboard > 系统管理 > System > SonarQube servers配置项

设置你的SonarQube信息,第一次添加的时候点击“添加按钮没反应”直接先点击保存

在这里插入图片描述

重新进入配置,这时就可以添加Jenkins凭据了,支持多种方式,这里我是用令牌的方式
在这里插入图片描述

来到SonarQube进入个人账户,生成令牌
在这里插入图片描述

复制到Jenkins的Secret处,描述是干嘛用的,待会要选择
在这里插入图片描述

选择刚刚创建的凭据保存
在这里插入图片描述

任务配置

进到我们之前创建好mytest任务配置中的Build Steps,添加一个Execute SonarQube Scanner构建步骤

在这里插入图片描述
设置参数,jdk选择我们内置的jdk1.8,然后把构建步骤拖到Maven的下面

sonar.projectname=${JOB_NAME}:项目名称设置为我们任务名称(当前任务名称叫mytest)

sonar.projectKey=${JOB_NAME}:这个key一般和项目名称一致即可,不设置的话报错

sonar.source=./:源码位置在当前位置

sonar.java.binaries=target:编译过后的文件在什么位置,target目录下

sonar.projectname=${JOB_NAME}
sonar.projectKey=${JOB_NAME}
sonar.source=./
sonar.java.binaries=target

在这里插入图片描述

构建任务

在我们配置的mytest任务,选择版本开始构建
在这里插入图片描述

构建成功并发布了项目,页面正常访问

Started by user 我是真滴帅
Running as SYSTEM
Building in workspace /var/jenkins_home/workspace/mytest
The recommended git tool is: NONE
No credentials specified
 > git rev-parse --resolve-git-dir /var/jenkins_home/workspace/mytest/.git # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url http://192.168.170.111:8888/root/jenkins-cicd-mytest.git # timeout=10
Fetching upstream changes from http://192.168.170.111:8888/root/jenkins-cicd-mytest.git
 > git --version # timeout=10
 > git --version # 'git version 2.30.2'
 > git fetch --tags --force --progress -- http://192.168.170.111:8888/root/jenkins-cicd-mytest.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/main^{commit} # timeout=10
Checking out Revision 971357ca89845b6f57327412c0975cbcc557e98c (refs/remotes/origin/main)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 971357ca89845b6f57327412c0975cbcc557e98c # timeout=10
Commit message: "修改index.html内容,用于区别v1.0.0"
 > git rev-list --no-walk 971357ca89845b6f57327412c0975cbcc557e98c # timeout=10
[mytest] $ /bin/sh -xe /tmp/jenkins16055891148945526156.sh
+ git checkout v1.0.1
HEAD is now at 971357c 修改index.html内容,用于区别v1.0.0
[mytest] $ /var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/maven/bin/mvn clean package -DskipTests
[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------------< com.monster:mytest >-------------------------
[INFO] Building mytest 0.0.1-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] Parameter 'archive' is unknown for plugin 'spring-boot-maven-plugin:2.6.13:repackage (repackage)'
[INFO] 
[INFO] --- clean:3.2.0:clean (default-clean) @ mytest ---
[INFO] Deleting /var/jenkins_home/workspace/mytest/target
[INFO] 
[INFO] --- resources:3.3.1:resources (default-resources) @ mytest ---
[INFO] Copying 2 resources from src/main/resources to target/classes
[INFO] 
[INFO] --- compiler:3.8.1:compile (default-compile) @ mytest ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to /var/jenkins_home/workspace/mytest/target/classes
[INFO] 
[INFO] --- resources:3.3.1:testResources (default-testResources) @ mytest ---
[INFO] skip non existing resourceDirectory /var/jenkins_home/workspace/mytest/src/test/resources
[INFO] 
[INFO] --- compiler:3.8.1:testCompile (default-testCompile) @ mytest ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /var/jenkins_home/workspace/mytest/target/test-classes
[INFO] 
[INFO] --- surefire:3.2.2:test (default-test) @ mytest ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- jar:3.3.0:jar (default-jar) @ mytest ---
[INFO] Building jar: /var/jenkins_home/workspace/mytest/target/mytest.jar
[INFO] 
[INFO] --- spring-boot:2.6.13:repackage (repackage) @ mytest ---
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.754 s
[INFO] Finished at: 2024-03-13T07:39:35Z
[INFO] ------------------------------------------------------------------------
[mytest] $ /var/jenkins_home/sonar-scanner/bin/sonar-scanner -Dsonar.host.url=http://192.168.170.111:9000 ******** -Dsonar.projectKey=mytest -Dsonar.projectname=mytest -Dsonar.java.binaries=target -Dsonar.source=./ -Dsonar.projectBaseDir=/var/jenkins_home/workspace/mytest
INFO: Scanner configuration file: /var/jenkins_home/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 5.0.1.3006
INFO: Java 17.0.7 Eclipse Adoptium (64-bit)
INFO: Linux 3.10.0-1160.el7.x86_64 amd64
INFO: User cache: /var/jenkins_home/.sonar/cache
INFO: Analyzing on SonarQube server 9.2.3
INFO: Default locale: "en", source code encoding: "UTF-8"
INFO: Load global settings
INFO: Load global settings (done) | time=66ms
INFO: Server id: 54000601-AYjKh1Zs1hD1Rss9XdjF
INFO: User cache: /var/jenkins_home/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=38ms
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=117ms
INFO: Process project properties
INFO: Process project properties (done) | time=1ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=1ms
INFO: Project key: mytest
INFO: Base dir: /var/jenkins_home/workspace/mytest
INFO: Working dir: /var/jenkins_home/workspace/mytest/.scannerwork
INFO: Load project settings for component key: 'mytest'
INFO: Load project branches
INFO: Load project branches (done) | time=8ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=8ms
INFO: Load branch configuration
INFO: Load branch configuration (done) | time=1ms
INFO: Auto-configuring with CI 'Jenkins'
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=55ms
INFO: Auto-configuring with CI 'Jenkins'
INFO: Load active rules
INFO: Load active rules (done) | time=2593ms
INFO: Indexing files...
INFO: Project configuration:
INFO: 10 files indexed
INFO: 14 files ignored because of scm ignore settings
INFO: Quality profile for java: Easyspeed
INFO: Quality profile for web: Sonar way
INFO: Quality profile for xml: Sonar way
INFO: Quality profile for yaml: Sonar way
INFO: ------------- Run sensors on module mytest
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=26ms
INFO: Sensor JavaSensor [java]
INFO: Configured Java source version (sonar.java.source): none
INFO: JavaClasspath initialization
INFO: JavaClasspath initialization (done) | time=7ms
INFO: JavaTestClasspath initialization
INFO: JavaTestClasspath initialization (done) | time=0ms
INFO: Java "Main" source files AST scan
INFO: 5 source files to be analyzed
INFO: Load project repositories
INFO: Load project repositories (done) | time=9ms
INFO: 5/5 source files have been analyzed
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.
INFO: Java "Main" source files AST scan (done) | time=1051ms
INFO: No "Test" source files to scan.
INFO: No "Generated" source files to scan.
INFO: Sensor JavaSensor [java] (done) | time=1283ms
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=2ms
INFO: Sensor IaC CloudFormation Sensor [iac]
INFO: 0 source files to be analyzed
INFO: 0/0 source files have been analyzed
INFO: Sensor IaC CloudFormation Sensor [iac] (done) | time=21ms
INFO: Sensor CSS Rules [javascript]
WARN: Error when running: 'node -v'. Is Node.js available during analysis?
INFO: Sensor CSS Rules [javascript] (done) | time=1763ms
INFO: Sensor C# Project Type Information [csharp]
INFO: Sensor C# Project Type Information [csharp] (done) | time=0ms
INFO: Sensor C# Analysis Log [csharp]
INFO: Sensor C# Analysis Log [csharp] (done) | time=12ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=0ms
INFO: Sensor SurefireSensor [java]
INFO: parsing [/var/jenkins_home/workspace/mytest/target/surefire-reports]
INFO: Sensor SurefireSensor [java] (done) | time=1ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=50ms
INFO: Sensor XML Sensor [xml]
INFO: 1 source file to be analyzed
INFO: 1/1 source file has been analyzed
INFO: Sensor XML Sensor [xml] (done) | time=222ms
INFO: Sensor VB.NET Project Type Information [vbnet]
INFO: Sensor VB.NET Project Type Information [vbnet] (done) | time=0ms
INFO: Sensor VB.NET Analysis Log [vbnet]
INFO: Sensor VB.NET Analysis Log [vbnet] (done) | time=13ms
INFO: Sensor VB.NET Properties [vbnet]
INFO: Sensor VB.NET Properties [vbnet] (done) | time=0ms
INFO: Sensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerPullRequestPropertySensor
INFO: Sensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerPullRequestPropertySensor (done) | time=1ms
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=7ms
INFO: Sensor Java CPD Block Indexer
INFO: Sensor Java CPD Block Indexer (done) | time=18ms
INFO: SCM Publisher SCM provider for this project is: git
INFO: SCM Publisher 8 source files to be analyzed
INFO: SCM Publisher 8/8 source files have been analyzed (done) | time=118ms
INFO: CPD Executor 3 files had no CPD blocks
INFO: CPD Executor Calculating CPD for 3 files
INFO: CPD Executor CPD calculation finished (done) | time=6ms
INFO: Analysis report generated in 103ms, dir size=102.3 kB
INFO: Analysis report compressed in 29ms, zip size=26.0 kB
INFO: Analysis report uploaded in 1761ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://ci.hkeasyspeed.com/dashboard?id=mytest
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://ci.hkeasyspeed.com/api/ce/task?id=AY42uH06JVfWiirduY0h
INFO: Analysis total time: 10.537 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 11.509s
INFO: Final Memory: 19M/70M
INFO: ------------------------------------------------------------------------
SSH: Connecting from host [3821aea39450]
SSH: Connecting with configuration [应用服务器-170.111] ...
SSH: EXEC: completed after 21,212 ms
SSH: Disconnecting configuration [应用服务器-170.111] ...
SSH: Transferred 3 file(s)
Build step 'Send files or execute commands over SSH' changed build result to SUCCESS
Finished: SUCCESS

来到SonarQube平台,可以看见多了个mytest,配置的默认按我们的任务名称命名

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1514524.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

详解MySQL的MVCC(ReadView部分解析C++源码)

文章目录 1. 什么是MVCC2. MVCC核心组成&#xff08;三大件&#xff09;2.1 MVCC为什么需要三大件 3. 隐藏字段4. undo log4.1 模拟版本链数据形成过程 5. Read View5.1 m_ids5.2 m_creator_trx_id5.3 m_low_limit_id5.4 m_up_limit_id5.5 可见性分析算法 6. MVCC流程模拟6.1 R…

三、NLP中的句子关系判断

句子关系判断是指判断句子是否相似&#xff0c;是否包含&#xff0c;是否是问答关系等&#xff0c;常应用在文本去重、检索&#xff08;用户输入和文档的相关性&#xff09;、推荐&#xff08;和用户喜好文章是否相似&#xff09;等场景中。 3.0、文本相似度计算 3.0.0 传统机…

白嫖AWS云服务器,验证、注册指南

背景 不知道你想不想拥有一台属于自己的云服务器呢&#xff0c;拥有一台自己的云服务器可以建站&#xff0c;可以在上面搭建个人博客&#xff0c;今天我就来教大家如何申请亚马逊 AWS 免费云服务器&#xff0c;这个云服务器可以长达12个月的免费。而且到期后可以继续换个账号继…

Vulnhub - DC-1

希望和各位大佬一起学习&#xff0c;如果文章内容有错请多多指正&#xff0c;谢谢&#xff01; 个人博客链接&#xff1a;CH4SER的个人BLOG – Welcome To Ch4sers Blog DC-1 靶机下载地址&#xff1a;DC: 1 ~ VulnHub 0x01 信息收集 Nmap扫描目标主机&#xff0c;发现开…

OPENCV(0-1之0.2)

OPENCV-0.2 学习安排图像基础像素访问和修改像素值 色彩空间转换RGB到灰度的转换RGB到HSV的转换 图像操作裁剪缩放旋转和翻转 图像滤波平滑和模糊图像边缘检测 图像变换仿射变换透视变换 总结 官方文档 学习安排 图像基础 像素&#xff1a;了解像素的概念&#xff0c;包括像素…

Filebeat(Beats)详细介绍与使用

1. 什么是 Beats? Beats 是开源数据传送器&#xff0c;将其作为代理安装在服务器上&#xff0c;以将操作数据发送到 Elasticsearch。 Elastic提供Beats用于捕获&#xff1a; 审核数据&#xff1a;Auditbeat 日志文件和日志&#xff1a;Filebeat 云数据&#xff1a;Functio…

【物联网学习笔记】CubeMx6.10+STM32F407ZGT6+LWIP最最最基础配置

使用正点原子探索者开发板 板载芯片&#xff1a;STM32F407ZGT6 PHY芯片&#xff1a;LAN8720 LWIP版本&#xff1a;2.1.2 本次目标&#xff1a;先ping通开发板再说&#xff01; 文章目录 一、CubeMX配置1、时钟配置2、ETH配置3、LWIP配置4、添加LAN8720的复位引脚 二、Keil工…

单链表——增删查改

本节复习链表的增删查改 首先&#xff0c; 链表不是连续的&#xff0c; 而是通过指针联系起来的。 如图&#xff1a; 这四个节点不是连续的内存空间&#xff0c; 但是彼此之间使用了一个指针来连接。 这就是链表。 现在我们来实现链表的增删查改。 目录 单链表的全部接口…

JVM之调优(一)

背景&#xff1a;生产环境由于堆内存较大&#xff0c;fullgc 垃圾回收导致程序卡顿问题&#xff08;假死&#xff09; 目录 一、程序卡顿导致的影响 前端页面空白后端数据重复 二、解决方法 降低堆内存大小使用合适的垃圾回收器&#xff08;可以尝试&#xff0c;还未进行测试…

【毕设级项目】基于嵌入式的智能家居控制板(完整工程资料源码)

基于嵌入式的智能家居控制板演示效果 基于嵌入式的智能家居控制板 前言&#xff1a; 随着科技的不断进步&#xff0c;物联网技术得到了突飞猛进的发展。智能家居是物联网技术的典型应用领域之一。智能家居系统将独立家用电器、安防设备连接成一个具有思想的整体&#xff0c;实现…

Android Studio入门——页面跳转

1.工程目录 2.MainActivity package com.example.demo01;import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.TextView;import androidx.appcompat.app.AppCompatActivity;public class MainActivity extends AppCo…

数据集成工具 ---- datax 3.0

1、datax: 是一个异构数据源离线同步工具&#xff0c;致力于实现关系型数据库&#xff08;mysql、oracle等&#xff09;hdfs、hive、hbase等各种异构数据源之间的数据同步 2、参考网址文献&#xff1a; https://github.com/alibaba/DataX/blob/master/introduction.mdhttps:/…

pycharm配置解释器

pycharm配置解释器 1.mac配置解释器 1.mac配置解释器

【C++庖丁解牛】STL简介 | string容器初次见面

&#x1f341;你好&#xff0c;我是 RO-BERRY &#x1f4d7; 致力于C、C、数据结构、TCP/IP、数据库等等一系列知识 &#x1f384;感谢你的陪伴与支持 &#xff0c;故事既有了开头&#xff0c;就要画上一个完美的句号&#xff0c;让我们一起加油 目录 1. 什么是STL2. STL的版本…

扫描全能王发布2023“绿色数据”:减碳超12万吨,相当于多种700万棵树

近年来&#xff0c;“绿色转型”“低碳生活”成为全民热议话题。从全国覆盖率越来越高的“垃圾分类”&#xff0c;到蓬勃发展的“无纸化办公”&#xff0c;低碳生活、绿色消费的环保风尚不断兴起。植树节将至&#xff0c;合合信息旗下扫描全能王发布了年度用户文档扫描数据&…

详细分析Mysql中的LOCATE函数(附Demo)

目录 1. 基本概念2. Demo3. 实战 1. 基本概念 LOCATE()函数在SQL中用于在字符串中查找子字符串的位置 它的一般语法如下&#xff1a; LOCATE(substring, string, start)LOCATE()函数返回子字符串在主字符串中第一次出现的位置 如果未找到子字符串&#xff0c;则返回0 具体的…

如何在群晖用Docker本地搭建Vocechat聊天服务并无公网ip远程交流协作

文章目录 1. 拉取Vocechat2. 运行Vocechat3. 本地局域网访问4. 群晖安装Cpolar5. 配置公网地址6. 公网访问小结 7. 固定公网地址 如何拥有自己的一个聊天软件服务? 本例介绍一个自己本地即可搭建的聊天工具,不仅轻量,占用小,且功能也停强大,它就是Vocechat. Vocechat是一套支持…

【BFS二叉树】113路径总和II

113路径总和 II 给你二叉树的根节点 root 和一个整数目标和 targetSum &#xff0c;找出所有 从根节点到叶子节点 路径总和等于给定目标和的路径。 思路&#xff1a; 题目最终输出的是路径&#xff0c;因此用BFS遍历的时候&#xff0c;需要记录走到每个节点的路径&#xff1…

ISIS单区域实验简述

ISIS 中间系统到中间系统&#xff0c;也是链路状态协议&#xff0c;工作在数据链路层&#xff0c;不依赖IP地址&#xff1b;与OSPF一样采用最短路径SPF算法&#xff0c;收敛速度快。 实验基础配置&#xff1a; r1: sys sysname r1 undo info enable int g0/0/0 ip add 12.1.1.1…

基于XMind的E-R图制作【笔记】

基于XMind的E-R图制作【笔记】 前言版权基于XMind的E-R图制作1.打开XMind2.选择模板3.插入一个自由主题4.为它插入子主题5.快速插入子主题6. 统一设置子主题样式 最后 前言 2024-3-11 10:36:33 以下内容源自《【创作模板】》 仅供学习交流使用 版权 禁止其他平台发布时删除…