通过pipeline配置sonar自动化实现过程解析

网友投稿 679 2023-03-07

通过pipeline配置sonar自动化实现过程解析

通过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 stjrhcrlep'

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

}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:微信官方文档小程序(微信官方文档 小程序)
下一篇:SpringBoot参数校验与国际化使用教程
相关文章

 发表评论

暂时没有评论,来抢沙发吧~