-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
125 lines (112 loc) · 3.6 KB
/
Jenkinsfile
File metadata and controls
125 lines (112 loc) · 3.6 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
void notifySlack(String status, String color ) {
slackSend(
color: color, message: status + ' : ' + "${env.JOB_NAME} [${env.BUILD_NUMBER}] (${env.BUILD_URL})"
)
}
pipeline {
agent any
options {
ansiColor('xterm')
}
tools {
gradle 'gradle 7.1'
}
stages {
stage('Checkout') {
steps {
git branch: 'develop', credentialsId: 'minsoo',
url: 'https://github.com/Software-Development-Practices/gradle-invaders.git'
}
}
stage('Build') {
steps {
notifySlack('STARTED', '#0000FF')
sh '''
chmod +x gradlew
./gradlew build -x test
'''
}
}
stage('Test') {
steps {
script {
try {
sh './gradlew test'
} catch (error) {
echo 'Test Failed'
}
}
}
}
stage('SonarQube analysis') {
steps {
withSonarQubeEnv('SonarQube-Server') {
sh '''
./gradlew sonarqube \
-Dsonar.projectKey=jenkins \
-Dsonar.host.url=http://34.64.148.169:9000 \
-Dsonar.login=2a553e7506c70332bd69f03407b1d3b53730e9b8
'''
}
}
}
stage('SonarQube Quality Gate') {
steps {
timeout(time: 1, unit: 'MINUTES') {
script {
echo 'Start~~~~'
def qg = waitForQualityGate()
echo "Status: ${qg.status}"
if (qg.status != 'OK') {
echo "NOT OK Status: ${qg.status}"
slackSend(
channel: '#ci-테스트-알림',
color: '#FF0000',
message: 'SonarQube Status Not OK'
)
error "Pipeline aborted due to quality gate failure: ${qg.status}"
} else {
echo "OK Status: ${qg.status}"
slackSend(
channel: '#ci-테스트-알림',
color: '#00FF00',
message: 'SonarQube Status OK'
)
}
echo 'End~~~~'
}
}
}
}
}
post {
success {
notifySlack('SUCCESS', '#00FF00')
}
unstable {
notifySlack('UNSTABLE', '#FFFF00')
}
failure {
notifySlack('FAILED', '#FF0000')
}
always {
archiveArtifacts artifacts: 'build/libs/**/*.jar', fingerprint: true
script {
def summary = junit testResults: '**/build/test-results/**/*.xml', skipMarkingBuildUnstable: true,
skipPublishingChecks: true,
healthScaleFactor: 1.0
slackSend(
channel: '#ci-테스트-알림',
color: '#007D00',
message: """
_BUILD SUMMARY_
*Test Summary* - ${summary.totalCount}
Failures: ${summary.failCount}
Skipped: ${summary.skipCount}
Passed: ${summary.passCount}
"""
)
}
}
}
}