Jenkins+SonarQube代码审查
2023-09-27 14:21:10 时间
1. 环境
Centos 7
Jenkins
SonarQube
7.9
2. SonarQube
生成token
SonarQube
默认账户是admin/admin
创建token
个人头像-->My Account
-->Security
700ba7c1c925ec53ff96159a9c84bf49040c34c0
3. Jenkins
安装SonarQube Scanner
插件
4. Jenkins
添加SonarQube
凭证
5. Jenkins
进行SonarQube
配置
Manage Jenkins
->Configure System
->SonarQube servers
应用,保存
Jenkins
安装SonarQube-scanner
Manage Jenkins
->Global Tool Configuration
保存,应用
6. SonaQube
关闭审查结果上传到SCM
功能
7. 在项目添加SonaQube
代码审查(非流水线项目)
在现有的非流水线项目中添加构建步骤:
# must be unique in a given SonarQube instance
sonar.projectKey=web_demo_freestyle
# this is the name and version displayed in the SonarQube UI. Was mandatory
prior to SonarQube 6.1.
sonar.projectName=web_demo_freestyle
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set.
sonar.sources=.
sonar.java.binaries=./target/classes
sonar.exclusions=**/test/**,**/target/**
sonar.java.source=11
sonar.java.target=11
# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
应用,保存
点击Build Now
8. 在项目添加SonaQube
代码审查(流水线项目)
1. 项目根目录下,创建sonar-project.properties
文件
# must be unique in a given SonarQube instance
sonar.projectKey=web_demo_pipeline
# this is the name and version displayed in the SonarQube UI. Was mandatory
prior to SonarQube 6.1.
sonar.projectName=web_demo_pipeline
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set.
sonar.sources=.
sonar.java.binaries=./target/classes
sonar.exclusions=**/test/**,**/target/**
sonar.java.source=1.8
sonar.java.target=1.8
# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
2. 修改Jenkinsfile
,加入SonarQube
代码审查阶段
pipeline {
agent any
stages {
stage('pull code') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/${branch}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'cce455e2-ba69-459e-93bc-c58ce1e6278f', url: 'ssh://git@192.168.2.4:23456/itheima_group/web_demo.git']]])
}
}
stage('build code') {
steps {
sh label: '', script: 'mvn clean package'
}
}
stage('check code') {
steps {
script {
scannerHome = tool 'sonar-scaner'
}
withSonarQubeEnv('sonarqube') {
sh "${scannerHome}/bin/sonar-scanner"
}
}
}
stage('deploy code') {
steps {
deploy adapters: [tomcat9(credentialsId: 'da6aa960-cb2b-415f-a31e-e161ba704f28', path: '', url: 'http://192.168.2.5:8080')], contextPath: null, war: 'target/*.war'
}
}
}
post {
always {
emailext body: '${FILE,path="email.html"}', subject: '构建通知:${PROJECT_NAME} - Build # ${BUILD_NUMBER} - ${BUILD_STATUS}!', to: '508110504@qq.com'
}
}
}
提交gitlab
,触发Jenkins
的Build
相关文章
- SonarQube4.4+Jenkins进行代码检查实例之三-单元測试分析
- Jenkins与网站代码上线解决方案
- 自动化代码审查平台: 基于Docker Compose整合Jenkins + SonarQube
- Jenkins的job远程触发另一个Jenkins上的job
- java jenkins
- 阿里内网最新实战手册,7 大核心组件详解 SpringCloud+Jenkins+K8S
- jenkins管理
- 修改Jenkins用户的密码
- 单机微服务整合Jenkins的代码准备
- Jenkins邮件通知
- 【Jenkins自动化部署】Windows节点Apache+Django服务自动化构建
- Jenkins+GitHub报错hudson.plugins.git.GitException: Failed to fetch from GitHub 443
- Jenkins上传代码到gitee零碎笔记
- jenkins里下载代码时出现代码在不同的git库里面,怎么将不同位置的不同代码下载到不同本地目录下
- 使用jenkins+sonar进行代码扫描,并发送自定义邮件
- docker中安装Jenkins
- jenkins 升级后无法启动
- Jenkins 替换pom发布
- Jenkins配置基于角色的项目权限管理--转
- jenkins with gitblit and .net framework and windows
- jenkins构建,拉取不到最新版本代码,报clock of the subversion server appears to be out of sync
- jenkins实战(二):构建自由风格的maven项目