Jenkins pipeline集成代码质量扫描

sonar-scanner下载

可以通过jenkins插件自动下载,也可以手动下载,我这里手动下载
下载地址:https://github.com/SonarSource/sonar-scanner-cli/releases/tag/3.2.0.1227
在这里插入图片描述

配置文件

conf/sonar-scanner.properties

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

#SonarQube服务器地址
sonar.host.url=http://127.22.22.22:9000

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

项目配置

在项目的根目录下新增 sonar-project.properties文件
在这里插入图片描述

配置详情

#项目key (必填项)
sonar.projectKey=temp-docker
#项目名称和版本(必填项)
sonar.projectName=temp-docker
sonar.projectVersion=1.0
#源码位置
sonar.sources=src/
#编译后的class位置(必填项,旧版本此项可不填,建议还是填入,相对路径同上)
sonar.java.binaries=target/classes
//排除的扫描的文件路径
sonar.exclusions=src/test/**
//源码JDK版本
sonar.java.source=1.8
sonar.java.target=1.8
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8

pipeline集成

pipeline {

    agent any
    stages {
        stage('代码检出') {
            steps {
                echo 'checkout'
                checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '',
                          locations: [[cancelProcessOnExternalsFail: true, credentialsId: 'ee2836e1-b734-4ccf-9bb7-035b735dd7b4', depthOption: 'infinity', ignoreExternalsOption: true, local: '.',
                                       remote: '${svn_url}']], quietOperation: true, workspaceUpdater: [$class: 'UpdateUpdater']])
            }
        }
        stage('编译构建') {
            steps {
                echo 'Building'
                sh 'mvn clean install -Dmaven.test.skip=true '
               

            }
        }

       stage('代码质量扫描') {
              steps{
                
                 sh "/data/sonar-scanner-3.2.0.1227-linux/bin/sonar-scanner"
               }

       }
        <!--stage('发布') {
              steps{
                
            
               }

       }-->
    }
}

执行结果

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值