DevOps-SonarQube整合Jenkins

下载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.mzph.cn/news/742250.shtml

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

相关文章

学习笔记——计算机网络(Internet、网络边缘)

一、Internet 网络是由多个计算机和其他网络设备通过通信链路相互连接而形成的互联网&#xff0c;用于实现数据传输和资源共享。它是现代信息社会中不可或缺的基础设施。 1.计算机网络&#xff1a; 通过通信链路连接&#xff1b; 以共享资源为目标&#xff1b; 资源包括&a…

基于Web的论文管理系统设计

目 录 目 录 III 摘 要 V 关键词 V Abstract VI Key Word VI 第一章 绪论 6 1.1系统设计背景 1 1.2系统设计目的与意义 1 1.3国内外现状 2 1.4本文结构 3 第二章 需求分析 3 2.1系统需求分析 4 2.2系统角色设计 4 第三章 系统开发技术 4 3.1 PHP语言简介和特点 5 3.2 Mysql数据…

【项目笔记】java微服务:黑马头条(day02)

文章目录 app端文章查看&#xff0c;静态化freemarker,分布式文件系统minIO1)文章列表加载1.1)需求分析1.2)表结构分析1.3)导入文章数据库1.3.1)导入数据库1.3.2)导入对应的实体类 1.4)实现思路1.5)接口定义1.6)功能实现1.6.1)&#xff1a;导入heima-leadnews-article微服务&am…

学C还是学C++?

计算机专业学生&#xff0c;大一上学期学习了C语言&#xff0c;下学期学校要学C&#xff0c;请问我寒假继续深入学习C还是提前学C,大佬们有什么建议吗&#xff1f;&#xff08;个人感觉C学的不是很明白&#xff0c;链表文件什么的还不是很懂…&#xff09; 这个并没有一个统一的…

流量池增长(6)

DMP和游戏化思维 流量的运营与挖掘 DMP: Data Management Platform&#xff0c;是一种用户数据标签化的管理和应用平台 DMP的价值 精准营销运营优化 建立DMP 用户标签化&#xff1a;与其他企业进行数据标签的撞库&#xff0c;进行精准的广告投放管理&#xff1a;执行营销策略…

7-3 截取字符串7-5 单词倒排

7-3 截取字符串&#xff08;分数 25&#xff09; 作者 刘琦 单位 天津城建大学 用户在三行中分别输入一个字符串s和两个整数m,n&#xff0c;输出字符串s中位于m和n&#xff08;包括m但不包括n&#xff0c;m<n&#xff09;之间的子字符串。 输入格式: 例如&#x…

数据库管理-第160期 Oracle Vector DB AI-11(20240312)

数据库管理160期 2024-03-12 数据库管理-第160期 Oracle Vector DB & AI-11&#xff08;20240312&#xff09;1 向量的函数操作to_vector()将vector转换为标准值vector_norm()vector_dimension_count()vector_dimension_format() 2 将向量转换为字符串或CLOBvector_seriali…

I O 流

IO流 啥是流 1、IO&#xff1a;输入 \ 输出流&#xff1a;一种抽象概念&#xff0c;是对数据传输的总称&#xff0c;也就是说&#xff0c;数据在设备间的传输称为流&#xff0c;流的本质&#xff0c;是数据传输IO流&#xff0c;就是用来&#xff0c;处理设备间的数据传输问题…

Android 使用adb操作WiFi相关指令

没有系统原生设置应用又需要调试WiFi功能时&#xff0c;可以使用如下指令来验证WiFi相关功能 最常用的就是 svc wifi enable/disable&#xff0c;再使用wpa_supplicant/wpa_cli来验证&#xff0c;但对于AP功能就没办法验证了&#xff0c;其实Android有组很强大的shell指令集&a…

明明jar包存在却报错找不到包名?两招教你解决java: 程序包org.springframework.context.annotation不存在问题!

一、问题提出 IDEA项目有时因为依赖库的问题出现出错&#xff1a; java: 程序包org.springframework.context.annotation不存在&#xff0c;如下图。 二、解决办法 方案1&#xff1a; 重新导入项目 ① 将项目中 .idea .iml 全部删除&#xff0c;项目重新导入 ② 用idea重新…

看完让你的RSA提升一个台阶 [GKCTF 2021]RRRRsa

阅读须知: 探索者安全团队技术文章仅供参考,未经授权请勿利用文章中的技术资料对任何计算机系统进行入侵操作,由于传播、利用本公众号所提供的技术和信息而造成的任何直接或者间接的后果及损失,均由使用者本人负责,作者不为此承担任何责任,如有侵权烦请告知,我们会立即删除…

2024计算机二级Python

1. 栈是先进先出&#xff0c;队是后进后出 2. 代码输出长度为5并不是\不占用位置&#xff0c;而是\与其后边的数字共同占用一个字符 3. 首先要弄清range函数此时表示的范围是前闭后开&#xff0c;不包含后面的数字&#xff0c;%函数表示的是余数&#xff0c;只有4是被整除的…

各种实用设置

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、命令行设置代理二、python包下载三、git设置代理 前言 一、命令行设置代理 export http_proxy"http://addr:port"二、python包下载 设置代理 …

sprintf函数和printf函数

在C语言中&#xff0c;sprintf函数和printf函数是两个非常常用的函数&#xff0c;它们都用于格式化输出字符串。尽管它们的名称很相似&#xff0c;但它们的功能却有所不同。 首先让我们来看一下printf函数。printf函数是C语言中最常用的输出函数之一&#xff0c;它用于将格式化…

批量处理数据:Java中的高效策略和实践

在处理大量数据时&#xff0c;尤其是在需要对数据库中的大批量记录进行更新时&#xff0c;有效的批处理策略是必不可少的。今天&#xff0c;我们将探讨一种在Java中批量更新数据的方法&#xff0c;并了解其在现实场景中的应用。 使用场景&#xff1a;重置视频标题 假设我们有…

案例分析篇15:软件开发方法考点(2024年软考高级系统架构设计师冲刺知识点总结系列文章)

专栏系列文章推荐: 2024高级系统架构设计师备考资料(高频考点&真题&经验)https://blog.csdn.net/seeker1994/category_12593400.html 【历年案例分析真题考点汇总】与【专栏文章案例分析高频考点目录】(2024年软考高级系统架构设计师冲刺知识点总结-案例分析篇-…

什么是Java中的线程?

Java中的线程 线程是操作系统能够进行运算调度的最小单位&#xff0c;它被包含在进程之中&#xff0c;是进程中的实际运作单位。一条线程指的是进程中一个单一顺序的控制流&#xff0c;一个进程中可以并发多个线程&#xff0c;每条线程并行执行不同的任务。线程是独立的&#…

ios xcode 15 PrivacyInfo.xcprivacy 隐私清单 查询应用使用的隐私api

1.需要升级mac os系统到13 兼容 xcode 15.1 2.升级mac os系统到14 兼容 xcode 15.3 3.选择 New File 4.直接搜索 privacy 能看到有个App Privacy 5.右击Add Row 7.直接选 Label Types 8.选中继续添加就能添加你的隐私清单了 苹果官网文档

【Java】关于equals 和 ==

一、 和 equals 区别 是运算符&#xff1b; 判读左右两端的数据是否一致&#xff0c; 比较基本数据类型比较的是值&#xff0c;比较引用数据类型比较的是地址值 &#xff1b; 默认判断的是两个对象的内存地址是否一致&#xff0c;一般用在基本数据类型上 equals equals 是ob…

每日一题——LeetCode1678.设计Goal解析器

方法一 splice 将字符串转为数组&#xff0c;对数组进行遍历&#xff0c;碰到G保持不变&#xff0c;继续循环&#xff0c;碰到 ( 看他后一位&#xff0c;是 ) 则删除两个元素&#xff0c;添加一个 o &#xff0c;不是则删除四个元素&#xff0c;添加元素 al &#xff0c;最后将…