温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用pipeline怎么自动化配置sonar

发布时间:2020-11-25 15:06:36 来源:亿速云 阅读:254 作者:Leah 栏目:开发技术

这篇文章给大家介绍使用pipeline怎么自动化配置sonar,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

1.sonar配置webhooks,

使用pipeline怎么自动化配置sonar

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

使用pipeline怎么自动化配置sonar

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'  }

}

关于使用pipeline怎么自动化配置sonar就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI