Jenkinsfile
1.73 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
pipeline {
agent any
tools {
maven 'maven-3.8'
}
stages {
stage('Checkout') {
steps {
git branch: 'main',
url: 'https://your-gitlab.com/pengchao/pengchao-calculator.git'
}
}
stage('Build & Test') {
steps {
sh 'mvn clean compile test'
}
post {
always {
junit 'target/surefire-reports/*.xml'
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'target/site/jacoco',
reportFiles: 'index.html',
reportName: 'JaCoCo Coverage Report'
])
}
}
}
stage('SonarQube Analysis') {
steps {
// 这里的 'sonarqube-server' 对应你在 Jenkins 系统配置中设置的 SonarQube 服务器名称
withSonarQubeEnv('sonarqube-server') {
sh 'mvn sonar:sonar'
}
}
}
stage('Quality Gate Check') {
steps {
timeout(time: 10, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
}
}
}
post {
always {
echo "Pengchao's的计算器项目构建完成 - 构建号: ${BUILD_NUMBER}"
}
success {
echo "✅ 代码质量检查通过!"
}
failure {
echo "❌ 构建失败,请检查日志"
}
}
}