[email protected] ~ / unzip sonar scanner c...">

当前位置:网站首页>Sonar series: continuous scanning through Jenkins integrated sonarqube (IV)

Sonar series: continuous scanning through Jenkins integrated sonarqube (IV)

2022-06-25 20:19:00 Bypass--

One 、 install SonarScanner

Download address :https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/

[[email protected] ~]# unzip sonar-scanner-cli-4.6.2.2472-linux.zip -d /opt/SonarScanner
[[email protected] ~]# vi /etc/profile
  #SonarScanner

  export Sonar_Home=/opt/SonarScanner/
  export PATH=$Sonar_Home/bin:$PATH

[[email protected] ~]# source /etc/profile

Two 、 stay Jenkins Install in Sonar plug-in unit

(1) Search for SonarQube Scanner, Find the plug-in , install

(2) stay Jenkins Middle configuration SonarQube

3、 ... and 、 Create pipeline tasks

(1) New assembly line

(2) To write Pipeline Script

pipeline{
    agent { node { label "build"}}

    stages{
        stage("CheckOut"){
            steps{
                script{
                    tools.PrintMes(" Pull the code ","green")
                    checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [],\
                        userRemoteConfigs: [[credentialsId: 'gitlab', url: 'https://gitlab.com/Bypass007/simple-java-maven-app.git']]])
                }
            }
        }
         stage("Build"){
            steps{
                script{
                    tools.PrintMes(" Perform packaging ","green")
                    mvnhome = tool 'M2'
                    sh "${mvnhome}/bin/mvn ${buildShell}"
                }
            }
         }
         stage("CodeScan"){
             steps{
                 script{
                    tools.PrintMes(" Code scanning ","green")
                    sonar.SonarScan("${JOB_NAME}","${JOB_NAME}","src")
                 }
             }
         }
    }

} 

 (3) Successfully build task , Passed code scanning .

Reference link :https://www.cnblogs.com/cjsblog/p/10740840.html

https://github.com/zeyangli/jenkinslibrary/blob/master/jenkinsfiles/ci.jenkinsfile

原网站

版权声明
本文为[Bypass--]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190501549764.html