You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
springboot-demo/Jenkinsfile

65 lines
2.4 KiB

pipeline {
agent any
tools {
// Install the Maven version configured as "M3" and add it to the path.
maven "maven"
}
stages {
stage('Get code') {
steps {
git url: 'https://gitea.xadocker.cn/resource/springboot-demo.git', branch: 'main', credentialsId: '867be6fa-88b1-4715-bcd6-3b2ebe671138'
}
}
stage("Build") {
steps {
sh "mvn -Dmaven.test.failure.ignore=true clean package"
}
post {
// If Maven was able to run the tests, even if some of the test
// failed, record the test results and archive the jar file.
success {
// junit '**/target/surefire-reports/TEST-*.xml'
archiveArtifacts 'target/*.jar'
}
}
}
stage('SonarQube analysis') {
steps {
script {
scannerHome = tool 'sonarqubescanner4.7'
}
withSonarQubeEnv('sonarqube') {
sh "${scannerHome}/bin/sonar-scanner " +
//在sonar中项目的名称
"-Dsonar.projectKey=helloworld " +
//在sonar中项目的名称
"-Dsonar.projectName=helloworld " +
"-Dsonar.sourceEncoding=UTF-8 " +
//项目类型
"-Dsonar.language=java " +
//需要过滤的文件类型
"-Dsonar.exclusions=**/*.css,**/*.js,**/*.xml " +
//sonar记录版本
"-Dsonar.projectVersion=2022.12.10-${BUILD_ID} " +
//需要检查代码的路径
"-Dsonar.sources=src/main/java/ " +
//需要检查代码源码路径
"-Dsonar.java.binaries=target/classes"
}
sleep(10)
// 这个睡眠时为了防止没有分析完成就去请求结果
timeout(time: 5, unit: 'MINUTES') {
script {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to a quality gate failure: ${qg.status}"
}
}
}
}
}
}
}