-
Notifications
You must be signed in to change notification settings - Fork 24
/
Jenkinsfile
305 lines (284 loc) · 13.2 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
def failedBuild = false
def minor_version = "8.3"
def version = "${minor_version}"
def changeUrl = env.CHANGE_URL
def slackResponse = null
def job = ""
def errors = []
def running = []
pipeline {
agent none
triggers {
cron('@midnight')
}
environment {
// TODO: automate
RUDDER_VERSION = "${minor_version}"
// we want it everywhere for plugins
MAVEN_ARGS = "--update-snapshots"
}
stages {
stage('Base tests') {
parallel {
stage('shell') {
agent {
dockerfile {
filename 'ci/shellcheck.Dockerfile'
}
}
steps {
script {
running.add("shell scripts")
}
sh script: './qa-test --shell', label: 'shell scripts lint'
sh script: './qa-test --scripts', label: 'shell postinst lint'
}
post {
always {
// linters results
recordIssues enabledForFailure: true, failOnError: true, sourceCodeEncoding: 'UTF-8',
tool: checkStyle(pattern: '.shellcheck/*.log', reportEncoding: 'UTF-8', name: 'Shell scripts')
}
failure {
script {
errors.add("shell scripts")
slackResponse = updateSlack(errors, running, slackResponse, version, changeUrl)
slackSend(channel: slackResponse.threadId, message: "Check shell scripts on all plugins failed - <${currentBuild.absoluteUrl}console|Console>", color: "#CC3421")
}
}
cleanup {
script {
running.remove("shell scripts")
}
}
}
}
stage('python') {
agent {
dockerfile {
filename 'ci/pylint.Dockerfile'
}
}
steps {
script {
running.add("python scripts")
}
sh script: './qa-test --python', label: 'python scripts lint'
}
post {
failure {
script {
errors.add("python scripts")
slackResponse = updateSlack(errors, running, slackResponse, version, changeUrl)
slackSend(channel: slackResponse.threadId, message: "Check python scripts on all plugins failed - <${currentBuild.absoluteUrl}console|Console>", color: "#CC3421")
}
}
cleanup {
script {
running.remove("python scripts")
}
}
}
}
stage('typos') {
agent {
dockerfile {
filename 'ci/typos.Dockerfile'
additionalBuildArgs '--build-arg VERSION=1.24.5'
}
}
steps {
script {
running.add("check typos")
}
sh script: './qa-test --typos', label: 'check typos'
}
post {
failure {
script {
errors.add("check typos")
slackResponse = updateSlack(errors, running, slackResponse, version, changeUrl)
slackSend(channel: slackResponse.threadId, message: "Check typos on all plugins failed - <${currentBuild.absoluteUrl}console|Console>", color: "#CC3421")
}
}
cleanup {
script {
running.remove("check typos")
}
}
}
}
}
}
stage('Publish plugins commons') {
// only publish nightly on dev branches
when { anyOf { branch 'master'; branch 'branches/rudder/*'; branch '*-next' } }
agent {
dockerfile {
filename 'ci/plugins.Dockerfile'
additionalBuildArgs "--build-arg USER_ID=${env.JENKINS_UID}"
// set same timezone as some tests rely on it
// and share maven cache
args '-v /etc/timezone:/etc/timezone:ro -v /srv/cache/elm:/home/jenkins/.elm -v /srv/cache/maven:/home/jenkins/.m2'
}
}
steps {
script {
running.add("Publish - common plugin")
}
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
dir('plugins-common') {
withMaven(globalMavenSettingsConfig: "1bfa2e1a-afda-4cb4-8568-236c44b94dbf",
// don't archive jars
options: [artifactsPublisher(disabled: true)]
) {
// we need to use $MVN_COMMAND to get the settings file path
sh script: 'make generate-pom'
sh script: '$MVN_CMD --update-snapshots clean install package deploy', label: "common deploy"
}
}
}
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
dir('plugins-common-private') {
withMaven(globalMavenSettingsConfig: "1bfa2e1a-afda-4cb4-8568-236c44b94dbf",
// don't archive jars
options: [artifactsPublisher(disabled: true)]
) {
// we need to use $MVN_COMMAND to get the settings file path
sh script: 'make generate-pom'
sh script: '$MVN_CMD --update-snapshots install package deploy', label: "private common deploy"
}
}
}
}
post {
failure {
script {
failedBuild = true
errors.add("Publish - common plugin")
slackResponse = updateSlack(errors, running, slackResponse, version, changeUrl)
slackSend(channel: slackResponse.threadId, message: "Error while publishing webapp - <${currentBuild.absoluteUrl}|Link>", color: "#CC3421")
}
}
cleanup {
script {
running.remove("Publish - common plugin")
}
}
}
}
stage('Build plugins') {
// only publish nightly on dev branches
when { anyOf { branch 'master'; branch 'branches/rudder/*'; branch '*-next' }; }
agent {
dockerfile {
filename 'ci/plugins.Dockerfile'
additionalBuildArgs "--build-arg USER_ID=${env.JENKINS_UID}"
// set same timezone as some tests rely on it
// and share maven cache
args '-v /etc/timezone:/etc/timezone:ro -v /srv/cache/elm:/home/jenkins/.elm -v /srv/cache/maven:/home/jenkins/.m2'
}
}
steps {
script {
def stageSuccess = [:]
def parallelStages = [:]
PLUGINS = sh (
script: 'make plugins-list',
returnStdout: true
).trim().split(' ')
PLUGINS.each { p ->
stage("Build ${p}") {
script {
running.add("Build - ${p}")
stageSuccess.put(p,false)
}
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
script {
dir("${p}") {
withMaven(globalMavenSettingsConfig: "1bfa2e1a-afda-4cb4-8568-236c44b94dbf",
// don't archive jars
options: [artifactsPublisher(disabled: true)]
) {
sh script: "export PATH=$MVN_CMD_DIR:$PATH && make ${(p == "cis" || p == "openscap") ? "" : "licensed"}", label: "build ${p} plugin"
if (changeRequest()) {
archiveArtifacts artifacts: '**/*.rpkg', fingerprint: true, onlyIfSuccessful: false, allowEmptyArchive: true
sshPublisher(publishers: [sshPublisherDesc(configName: 'publisher-01', transfers: [sshTransfer(execCommand: "/usr/local/bin/add_to_repo -r -t rpkg -v ${env.RUDDER_VERSION}-nightly -d /home/publisher/tmp/${p}-${env.RUDDER_VERSION}", remoteDirectory: "${p}-${env.RUDDER_VERSION}", sourceFiles: '**/*.rpkg')], verbose:true)])
}
}
}
stageSuccess.put(p,true)
}
}
script {
if (! stageSuccess[p]) {
errors.add("Build - ${p}")
failedBuild = true
slackResponse = updateSlack(errors, running, slackResponse, version, changeUrl)
slackSend(channel: slackResponse.threadId, message: "Error on plugin ${p} build - <${currentBuild.absoluteUrl}console|Console>", color: "#CC3421")
}
running.remove("Build - ${p}")
}
}
}
}
}
}
stage("Publish to repository") {
when { not { changeRequest() } }
agent any
steps {
script {
running.add("Publish - plugins")
}
sshPublisher(publishers: [sshPublisherDesc(configName: 'publisher-01', transfers: [sshTransfer(execCommand: "/usr/local/bin/publish -v \"${RUDDER_VERSION}\" -t plugins -u -m nightly")], verbose:true)])
}
post {
failure {
script {
errors.add("Publish - plugins")
slackResponse = updateSlack(errors, running, slackResponse, version, changeUrl)
slackSend(channel: slackResponse.threadId, message: "Publishing plugins failed - <${currentBuild.absoluteUrl}console|Console>", color: "#CC3421")
}
}
cleanup {
script {
running.remove("Publish - plugins")
}
}
}
}
stage('End') {
steps {
script {
updateSlack(errors, running, slackResponse, version, changeUrl)
if (failedBuild) {
error 'End of build'
} else {
echo 'End of build'
}
}
}
}
}
}
def updateSlack(errors, running, slackResponse, version, changeUrl) {
def msg ="*${version} - plugins* - <"+currentBuild.absoluteUrl+"|Link>"
if (changeUrl == null) {
def fixed = currentBuild.resultIsBetterOrEqualTo("SUCCESS") && currentBuild.previousBuild.resultIsWorseOrEqualTo("UNSTABLE")
if (errors.isEmpty() && running.isEmpty() && fixed) {
msg += " => All plugins built! :white_check_mark:"
def color = "good"
slackSend(channel: "ci", message: msg, color: color)
}
if (! errors.isEmpty()) {
msg += "\n*Errors* :x: ("+errors.size()+")\n • " + errors.join("\n • ")
def color = "#CC3421"
if (slackResponse == null) {
slackResponse = slackSend(channel: "ci", message: msg, color: color)
}
slackSend(channel: slackResponse.channelId, message: msg, timestamp: slackResponse.ts, color: color)
}
return slackResponse
}
}