-
Notifications
You must be signed in to change notification settings - Fork 10
/
Jenkinsfile
223 lines (206 loc) · 7.96 KB
/
Jenkinsfile
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
pipeline {
agent {
label 'gradle:6.3-jdk11'
}
parameters {
booleanParam(name: 'RELEASE', defaultValue: false, description: 'Enable this value to generate a release on this build')
choice(name: 'RELEASE_TYPE', choices: 'Patch\nMinor\nMajor', description: 'Increment major, minor, or patch version for release')
}
options {
timeout(time: 1, unit: "HOURS")
parallelsAlwaysFailFast()
}
environment {
CI = 'true'
}
stages {
stage('Preparing') {
steps {
echo "Running Preparing..."
// Default pipeline checkout behaviour does not fetch tags so we need to get them now
sh "git fetch --tags"
script {
env.FAILED_STAGE_NAME = env.STAGE_NAME
echo("IsRelease: ${params.RELEASE}, Releasing with increment: ${params.RELEASE_TYPE}")
if (params.RELEASE) {
sh "./gradlew createRelease -Prelease.versionIncrementer=increment${params.RELEASE_TYPE} -Prelease.disableChecks"
}
}
sh './gradlew currentVersion'
}
}
stage('Check') {
steps {
script {
env.FAILED_STAGE_NAME = env.STAGE_NAME
}
echo "Running Tests..."
sh './gradlew check --profile'
}
post {
always {
jacoco classPattern: "**/build/classes", execPattern: "**/build/jacoco/*.exec", sourcePattern: "**/src/main/kotlin"
junit allowEmptyResults: true, testResults: '**/build/test-results/**/*.xml'
publishCoverage adapters: [jacocoAdapter(mergeToOneReport: true, path: '**/build/reports/jacoco/test/jacocoTestReport.xml')]
}
}
}
stage('Static Code Analysis') {
parallel {
stage('SonarQube') {
steps {
script {
env.FAILED_STAGE_NAME = env.STAGE_NAME
}
withSonarQubeEnv('sonarQube') {
sh './gradlew sonarqube'
}
}
}
stage('NexusIQ') {
steps {
echo "TODO - NexusIQ is not implemented"
}
}
stage('Fortify') {
steps {
echo "TODO - Fortify is not implemented"
}
}
stage('owasp') {
steps {
echo "TODO - owasp is not implemented"
}
}
}
}
stage("Quality Gate") {
steps {
script {
env.FAILED_STAGE_NAME = env.STAGE_NAME
}
timeout(time: 30, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
}
}
stage('Build for F/H/R/*') {
when {
anyOf {
branch 'feature/*'
branch 'hotfix/*'
branch 'release/*'
changeRequest()
}
}
steps {
script {
env.FAILED_STAGE_NAME = env.STAGE_NAME
}
echo "Running Build for PR/Feature/Hotfix/Release/*..."
sh './gradlew build --profile'
}
}
stage('Publish for Develop') {
when {
branch 'develop'
}
steps {
script {
env.FAILED_STAGE_NAME = env.STAGE_NAME
if (params.RELEASE) {
echo("Releasing with increment ${params.RELEASE_TYPE}")
}
}
echo "Running Publish for Develop..."
sh './gradlew publish'
timeout(time: 10, unit: "MINUTES") {
input(message: 'Build docker image?')
sh './gradlew jibBuildTar'
}
}
}
stage('Generate for Release') {
when {
branch 'release/*'
}
steps {
script {
env.FAILED_STAGE_NAME = env.STAGE_NAME
}
echo "TODO: Generate Changelog"
echo "TODO: Generate proto code"
}
}
stage('Deploy for Master') {
when {
branch 'main'
}
steps {
script {
env.FAILED_STAGE_NAME = env.STAGE_NAME
}
echo "Running Deploy for Master..."
sh './gradlew publish'
timeout(time: 1, unit: "HOURS") {
chatNotification('PROMPT', "*ACTION REQUIRED* Pipeline build ${env.BUILD_TAG} requesting input to deploy to *PRODUCTION*. Click _'Proceed'_ to deploy, click _'Abort'_ to skip deployment. Link to build: ${env.BUILD_URL}console")
input(message: 'Deploy this build to Production?')
sh './gradlew jib'
}
}
}
}
post {
success {
chatNotification('SUCCESS', "Successful !")
}
unstable {
chatNotification('UNSTABLE', "Unstable on stage *${env.FAILED_STAGE_NAME}* !")
}
failure {
chatNotification('FAILURE', "Failed on stage *${env.FAILED_STAGE_NAME}* !")
}
aborted {
chatNotification('ABORTED', "Aborted on stage *${env.FAILED_STAGE_NAME}* !")
}
always {
echo "Archive JARs:"
archiveArtifacts artifacts: '**/build/libs/*.jar', fingerprint: true
echo "Publish Demo Test Report:"
publishHTML([
allowMissing : false,
alwaysLinkToLastBuild: false,
keepAll : true,
reportDir : 'apps/demo/build/reports/tests/test',
reportFiles : 'index.html',
reportName : 'Gradle Test Report',
reportTitles : ''
])
echo "Publish Demo Coverage Reports:"
publishHTML([
allowMissing : false,
alwaysLinkToLastBuild: false,
keepAll : true,
reportDir : 'apps/demo/build/reports/jacoco/test/html',
reportFiles : 'profile-*.html',
reportName : 'Gradle Coverage Report',
reportTitles : ''
])
}
}
}
def chatNotification(String level, String msg) {
def GoogleWebhook = 'https://chat.googleapis.com/v1/spaces/xyz/messages?key=xyz&token=xyz'
def message = "Build <${env.BUILD_URL}|${env.JOB_NAME}#${env.BUILD_NUMBER}>/<${env.RUN_DISPLAY_URL}|BlueOcean>: ${msg}" as Object
if (level == 'SUCCESS') {
googlechatnotification notifySuccess: true, message: message, sameThreadNotification: true, url: GoogleWebhook;
} else if (level == 'UNSTABLE') {
googlechatnotification notifyUnstable: true, message: message, sameThreadNotification: true, url: GoogleWebhook;
} else if (level == 'FAILURE') {
googlechatnotification notifyFailure: true, message: message, sameThreadNotification: true, url: GoogleWebhook;
} else if (level == 'ABORTED') {
googlechatnotification notifyAborted: true, message: message, sameThreadNotification: true, url: GoogleWebhook;
} else if (level == 'PROMPT') {
googlechatnotification message: msg as Object, sameThreadNotification: true, url: GoogleWebhook;
}
}