pipeline配置sonar和自动化

1.sonar配置webhooks,

2.url填写jenkins的地址:http://jenkinsurl/sonarqube-webhook/

3.前提:jenkins配置好sonar的scanner服务地址

复制代码
node {  
    stage('gitcheckout') { 
        echo 'This is a gitcheckout step' 
                checkout poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'git-', url: 'http://gitlab..com/qingzhu-dev/workflow.git']]]
    }
    stage('sonar') { 
         echo 'This is a sonar step' 
         def sonarqubeScannerHome = tool name: 'sonar-scanner'
         echo sonarqubeScannerHome
                withSonarQubeEnv('sonar') {
                sh "${sonarqubeScannerHome}/bin/sonar-scanner -X "+
                "-Dsonar.host.url=${SONAR_HOST_URL} " +
                "-Dsonar.language=java " + 
                "-Dsonar.projectKey=workflow " + 
                "-Dsonar.projectName=workflow " + 
                "-Dsonar.projectVersion=$BUILD_NUMBER " + 
                "-Dsonar.sources=src/ " + 
                "-Dsonar.sourceEncoding=UTF-8 " + 
                "-Dsonar.java.binaries=target/ " + 
                "-Dsonar.exclusions=src/test/** " 
                
         }
    }
    stage("QualityGate") {
        echo 'QualityGate'
        // timeout(time: 1, unit: "HOURS") {       // 防止获取回调出现异常情况,设置超时时间
        //     def qg = waitForQualityGate()
        //     if (qg.status != 'OK') {
        //         error "Pipeline aborted due to quality gate failure: ${qg.status}"
        //     }
       // }
    }

    stage('Build') { 
        echo 'This is a build step'
        sh "/var/jenkins_home/apache-maven-3.6.0/bin/mvn clean package -U dockerfile:build dockerfile:push -Ptest -D maven.test.skip=true -f pom.xml -Dimage.tag=v$BUILD_NUMBER"
    }
      stage('Deploy') { 
        echo 'This is a deploy step'   
        sh "${dp}"
    }
    stage('Test') { 
        echo 'This is a test step'  
                checkout poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/qiaojiafei']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'git-', url: 'http://gitlab..com/qz-qa/qingzhucrmtest.git']]]
                sh  '/var/jenkins_home/apache-maven-3.6.0/bin/mvn clean test -DfailIfNoTests=false -Ptest'
    }

stage('report'){
echo 'This is a report'
allure includeProperties: false, jdk: 'jdk1.8', results: [[path: 'allure-results']]
sh 'rm -rf allure-report'
sh 'rm -rf allure-results'
}
stage('email'){
emailext body: 'test', subject: 'test', to: 'gexinwei@meizhu365.com'
}


}
复制代码

 

posted on   乔叶叶  阅读(4072)  评论(0编辑  收藏  举报

编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示