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,一经查实,立即删除!

相关文章

基于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…

数据库管理-第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…

明明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是被整除的…

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

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

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.选中继续添加就能添加你的隐私清单了 苹果官网文档

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

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

打工人狂喜,微信管理既如此简单

微信作为一款全民的社交软件&#xff0c;已经成为人们日常生活中必不可少的通讯工具。不仅个人使用广泛&#xff0c;很多企业也依赖微信进行业务沟通和客户服务。然而&#xff0c;对于企业用户来说&#xff0c;管理多个微信号确实带来了许多繁琐和不便之处。 但是&#xff01;…

【经验分享】创建团队编程训练区,发布编程打卡题及考核

总结&#xff1a; 1、在vijos平台上创建团队编程训练区&#xff0c;管理加入的成员&#xff0c;训练区内的资源仅对成员公开&#xff1b; 2、发布编程题让团队成员进行训练&#xff0c;能够实时查询成员通关情况&#xff1b; 3、能够想发布限时考试&#xff0c;对成员进行考核。…

Java毕业设计-基于spring boot开发的实习管理系统-毕业论文+答辩ppt(附源代码+演示视频)

文章目录 前言一、毕设成果演示&#xff08;源代码在文末&#xff09;二、毕设摘要展示1.开发说明2.需求分析3、系统功能结构 三、系统实现展示1、前台功能模块2、后台功能模块2.1 管理员功能2.2 教师功能2.3 学生功能2.4 实习单位功能 四、毕设内容和源代码获取总结 Java毕业设…

全面解析unityplayer.dll丢失的5种解决方法,轻松搞定dll丢失

在使用Unity开发的游戏或应用过程中&#xff0c;如果发现系统提示“找不到unityplayer.dll”文件&#xff0c;可能会引发一系列的问题与不便。这将直接导致游戏或应用程序无法正常启动运行&#xff0c;因为unityplayer.dll是Unity引擎的核心组件之一&#xff0c;负责处理关键的…

【C语言】三种方式实现字符串(char*)/字符数组(char[ ])输入输出

前言 做题时经常需要用到字符串&#xff0c;写篇笔记加强记忆&#xff0c;本文用 4个例子实现字符串的输入输出操作。 scanf(); 从键盘输入数据时&#xff0c;遇到 “空格”、“回车” 都会终止。若要接受空格&#xff0c;使用 gets(); 代替 scanf(); 多个 scanf(); 同时出现…

重建大师出现图中密集匹配失败的情况,是什么原因导致的?

可以检查瓦块是否位于测区边缘&#xff0c;边缘瓦块可以忽略&#xff1b;如果是中间区域的话&#xff0c;可能中间文件有异常&#xff0c;可以新建个reconstruction&#xff0c;然后单独提交失败的瓦块。 重建大师是一款专为超大规模实景三维数据生产而设计的集群并行处理软件&…

uniapp封装统一请求(get和post)

uniapp封装请求 request.js文件 import Vue from vue // 全局配置 import settings from ./settings.js function computedBaseUrl(url) {// console.log(url);return (url.indexOf(http) -1 ? settings.baseUrl : ) url }// 发送请求 export default (options) > {const…

初识C++类和对象(1)

1.定义类 我们使用class进行表示类&#xff0c;class后面的是类名rect&#xff0c;在类里面我们可以定义成员变量&#xff0c;这个题目我们是要去求长方形的周长和面积&#xff0c;我们定义长方形的长&#xff0c;和长方形的宽度&#xff1b; 我们定义了2个函数计算长方形的周…

数字化时代,企业数字化转型的突破口在哪里?

企业数字化转型的突破口在哪里&#xff1f; 从业TOB行业9年&#xff0c;根据我这些年的观察&#xff0c;我认为企业要想在数字化转型这件事上取得成绩&#xff0c;那么需要企业先从领导层培养数字化意识&#xff0c;然后从战略规划、文化转变、数据驱动、技术设施、人才培养等…

OpenCV学习笔记(五)——图片的缩放、旋转、平移、裁剪以及翻转操作

目录 图像的缩放 图像的平移 图像的旋转 图像的裁剪 图像的翻转 图像的缩放 OpenCV中使用cv2.resize()函数进行缩放&#xff0c;格式为&#xff1a; resize_imagecv2.resize(image,(new_w,new_h),插值选项) 其中image代表的是需要缩放的对象&#xff0c;(new_w,new_h)表…

mysql数据库(下)

目录 约束 约束的概念和分类 1、约束的概念&#xff1a; 2、约束的分类 1、主键约束 2、默认约束 3、非空约束 4、唯一约束 5、外键约束 约束 约束的概念和分类 1、约束的概念&#xff1a; 约束时作用于表中列上的规则&#xff0c;用于限制加入表的数据约束的存在保证…