SonarQube是一款静态代码分析、代码质量度量和漏洞检测的开源代码质量管理平台,它提供了许多功能,包括静态代码分析、代码覆盖率、复杂度分析、漏洞检测等。SonarQube可以集成到许多流行的编程语言和集成开发环境中,帮助开发人员创建高质量的软件项目。SonarQube以及依赖环境软件的安装已经在此系列文章的第一篇写过,这里只介绍如何配置和使用Jenkins+SonarQube进行代码质量检查。
流水线脚本如下:
node {
def mvnHome
stage('Preparation') { // for display purposes
// Get some code from a GitHub repository
echo "checkout from GitLab"
checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[credentialsId: 'git_username', url: 'http://127.0.0.1:9091/test/test.git']])
// Get the Maven tool.
// ** NOTE: This 'M3' Maven tool must be configured
// ** in the global configuration.
mvnHome = tool 'maven_j'
}
stage('SonarQube Analysis') {
echo "sonar test code"
withEnv(["MVN_HOME=$mvnHome"]) {
withSonarQubeEnv() {
sh "'$MVN_HOME/bin/mvn' clean verify sonar:sonar -Dsonar.projectKey=sonarTest -Dsonar.projectName='Sonar质量检查'"
}
}
}
stage('Build') {
echo "build test code"
// Run the maven build
withEnv(["MVN_HOME=$mvnHome"]) {
if (isUnix()) {
sh '"$MVN_HOME/bin/mvn" -Dmaven.test.failure.ignore clean package'
} else {
bat(/"%MVN_HOME%binmvn" -Dmaven.test.failure.ignore clean package/)
}
}
}
stage('Results') {
echo "end sonar testcode"
//junit '**/target/surefire-reports/TEST-*.xml'
// archiveArtifacts 'target/*.jar'
}
}
页面更新:2024-02-11
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号