forked from zowe/zowe-install-packaging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile.nightly
340 lines (309 loc) · 12.9 KB
/
Jenkinsfile.nightly
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#!groovy
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright IBM Corporation 2018, 2019
*/
node('ibm-jenkins-slave-nvm') {
def lib = library("jenkins-library").org.zowe.jenkins_shared_library
def SLACK_CHANNEL = '#zowe-build'
def ZOWE_RELEASE_REPOSITORY = 'libs-release-local'
def ZOWE_RELEASE_PATH = '/org/zowe/nightly'
def ZOWE_BUILD_NAME = 'zowe-install-packaging :: staging'
def ZOWE_BUILD_REPOSITORY = 'libs-snapshot-local'
def ZOWE_CLI_RELEASE_PATH = '/org/zowe/nightly/cli'
def ZOWE_CLI_BUILD_NAME = 'Zowe CLI Bundle :: master'
def ZOWE_CLI_BUILD_REPOSITORY = 'libs-snapshot-local'
def isStagingBranch = env && env.BRANCH_NAME == 'staging'
def sourceRegBuildInfo
def sourceSmpeBuildInfo
def sourceSmpeReadmeInfo
def cliSourceBuildInfo
def testRegBuildErrorUrl
def testSmpeBuildErrorUrl
def targetSmpeFullPath
def targetSmpeReadmeFullPath
def targetRegFullPath
def cliTargetFullPath
def pipeline = lib.pipelines.generic.GenericPipeline.new(this)
pipeline.admins.add("jackjia", "markackert")
// we have extra parameters for the pipeline
pipeline.addBuildParameter(
booleanParam(
name: 'TEST_RUN',
description: 'Test run will skip test cases and will not send out Slack message.',
defaultValue: isStagingBranch ? false : true
)
)
// we want to run daily on master branch
if (isStagingBranch) {
pipeline.addBuildOption(pipelineTriggers([cron("TZ=America/New_York\nH 23 * * *")]))
}
pipeline.setup(
packageName: 'org.zowe',
github: [
email : lib.Constants.DEFAULT_GITHUB_ROBOT_EMAIL,
usernamePasswordCredential : lib.Constants.DEFAULT_GITHUB_ROBOT_CREDENTIAL,
],
artifactory: [
url : lib.Constants.DEFAULT_ARTIFACTORY_URL,
usernamePasswordCredential : lib.Constants.DEFAULT_ARTIFACTORY_ROBOT_CREDENTIAL,
]
)
pipeline.createStage(
name : "Pre-Check",
isSkippable : true,
stage : {
echo "Checking last build of \"${ZOWE_BUILD_NAME}\" ..."
// check artifactory for latest build with SMP/e
try {
def latestBuild = pipeline.artifactory.getArtifact([
'pattern' : "${ZOWE_BUILD_REPOSITORY}/*/AZWE*.pax.Z",
'build-name' : ZOWE_BUILD_NAME
])
// extract build information
def buildNumber = latestBuild['build.number']
def buildTimestamp = latestBuild['build.timestamp']
long buildTimestampInt = buildTimestamp as Long
def currentTimestamp = sh(script: 'date +"%s"', returnStdout: true).trim()
long currentTimestampInt = currentTimestamp as Long
def timeElapse = (currentTimestampInt * 1000 - buildTimestampInt) / (3600 * 1000)
echo "Build #${buildNumber} is ${timeElapse} hours ago"
if (timeElapse < 22) { // how many hours we consider it's too old?
echo "Will skip re-build."
sourceSmpeBuildInfo = latestBuild
} else {
echo "Will need to re-build."
}
} catch (es) {
echo "getArtifact AZWE*.pax.Z failed: ${es}"
echo "Will need to re-build."
}
echo "Checking last CLI build of \"${ZOWE_CLI_BUILD_NAME}\" ..."
// check artifactory for latest CLI build
cliSourceBuildInfo = pipeline.artifactory.getArtifact([
'pattern' : "${ZOWE_CLI_BUILD_REPOSITORY}/*",
'build-name' : ZOWE_CLI_BUILD_NAME
])
},
timeout: [time: 2, unit: 'MINUTES']
)
pipeline.build(
name : "Zowe",
timeout : [time: 1, unit: 'HOURS'],
isSkippable : false,
operation : {
if (!sourceSmpeBuildInfo || !sourceSmpeBuildInfo['path']) {
echo "Building new driver ..."
// run build
def build_result = build(
job: '/zowe-install-packaging/staging',
parameters: [
booleanParam(name: 'BUILD_SMPE', value: true),
],
propagate: false
)
echo "Build result: ${build_result.result}"
if (build_result.result != 'SUCCESS') {
error "Failed to build a new Zowe driver, check failure details at ${build_result.absoluteUrl}"
}
// load build info
sourceSmpeBuildInfo = pipeline.artifactory.getArtifact([
'pattern' : "${ZOWE_BUILD_REPOSITORY}/*/AZWE*.pax.Z",
'build-name' : ZOWE_BUILD_NAME
])
} else {
echo "No need to build new driver."
}
}
)
pipeline.createStage(
name : "Load Build Info",
isSkippable : true,
shouldExecute : {
return sourceSmpeBuildInfo && sourceSmpeBuildInfo['path']
},
stage : {
sourceRegBuildInfo = pipeline.artifactory.getArtifact([
'pattern' : "${ZOWE_BUILD_REPOSITORY}/*/zowe-*.pax",
'build-name' : ZOWE_BUILD_NAME,
'build-number' : sourceSmpeBuildInfo['build.number']
])
sourceSmpeReadmeInfo = pipeline.artifactory.getArtifact([
'pattern' : "${ZOWE_BUILD_REPOSITORY}/*/AZWE*.txt",
'build-name' : ZOWE_BUILD_NAME,
'build-number' : sourceSmpeBuildInfo['build.number']
])
},
timeout: [time: 2, unit: 'MINUTES']
)
pipeline.test(
name : "Zowe Regular Build",
shouldExecute : {
return sourceRegBuildInfo && sourceRegBuildInfo['path'] &&
cliSourceBuildInfo && cliSourceBuildInfo['path']
},
operation : {
if (params.TEST_RUN) {
echo "Skip testing with parameters:\n\n" +
"STARTED_BY_AUTOMATION: true\n" +
"SKIP_RESET_IMAGE: true\n" +
"ZOWE_ARTIFACTORY_PATTERN: '${sourceRegBuildInfo.path}'\n" +
"ZOWE_ARTIFACTORY_BUILD: ''\n" +
"IS_SMPE_PACKAGE: false\n" +
"ZOWE_CLI_ARTIFACTORY_PATTERN: '${cliSourceBuildInfo.path}'\n" +
"ZOWE_CLI_ARTIFACTORY_BUILD: ''\n" +
"TEST_CASE_DEBUG_INFORMATION: 'test:*'\n" +
"Skip Stage: Lint: true\n" +
"Skip Stage: Audit: true\n" +
"Skip Stage: SonarQube Scan: true"
} else {
def test_result = build(
job: '/zowe-install-test/staging',
parameters: [
booleanParam(name: 'STARTED_BY_AUTOMATION', value: true),
booleanParam(name: 'SKIP_RESET_IMAGE', value: true),
string(name: 'ZOWE_ARTIFACTORY_PATTERN', value: sourceRegBuildInfo.path),
string(name: 'ZOWE_ARTIFACTORY_BUILD', value: ''),
booleanParam(name: 'IS_SMPE_PACKAGE', value: false),
string(name: 'ZOWE_CLI_ARTIFACTORY_PATTERN', value: cliSourceBuildInfo.path),
string(name: 'ZOWE_CLI_ARTIFACTORY_BUILD', value: ''),
string(name: 'TEST_CASE_DEBUG_INFORMATION', value: 'test:*'),
booleanParam(name: 'Skip Stage: Lint', value: true),
booleanParam(name: 'Skip Stage: Audit', value: true),
booleanParam(name: 'Skip Stage: SonarQube Scan', value: true)
],
propagate: false
)
echo "Test result: ${test_result.result}"
if (test_result.result != 'SUCCESS') {
testRegBuildErrorUrl = test_result.absoluteUrl
echo "Test failed on regular build ${sourceRegBuildInfo.path}, check failure details at ${test_result.absoluteUrl}"
}
}
},
allowMissingJunit : true,
timeout: [time: 2, unit: 'HOURS']
)
pipeline.test(
name : "Zowe SMP/e Build",
shouldExecute : {
return sourceSmpeBuildInfo && sourceSmpeBuildInfo['path'] &&
cliSourceBuildInfo && cliSourceBuildInfo['path']
},
operation : {
if (params.TEST_RUN) {
echo "Skip testing with parameters:\n\n" +
"STARTED_BY_AUTOMATION: true\n" +
"SKIP_RESET_IMAGE: true\n" +
"ZOWE_ARTIFACTORY_PATTERN: '${sourceSmpeBuildInfo.path}'\n" +
"ZOWE_ARTIFACTORY_BUILD: ''\n" +
"IS_SMPE_PACKAGE: true\n" +
"ZOWE_CLI_ARTIFACTORY_PATTERN: '${cliSourceBuildInfo.path}'\n" +
"ZOWE_CLI_ARTIFACTORY_BUILD: ''\n" +
"TEST_CASE_DEBUG_INFORMATION: 'test:*'\n" +
"Skip Stage: Lint: true\n" +
"Skip Stage: Audit: true\n" +
"Skip Stage: SonarQube Scan: true"
} else {
def test_result = build(
job: '/zowe-install-test/staging',
parameters: [
booleanParam(name: 'STARTED_BY_AUTOMATION', value: true),
booleanParam(name: 'SKIP_RESET_IMAGE', value: true),
string(name: 'ZOWE_ARTIFACTORY_PATTERN', value: sourceSmpeBuildInfo.path),
string(name: 'ZOWE_ARTIFACTORY_BUILD', value: ''),
booleanParam(name: 'IS_SMPE_PACKAGE', value: true),
string(name: 'ZOWE_CLI_ARTIFACTORY_PATTERN', value: cliSourceBuildInfo.path),
string(name: 'ZOWE_CLI_ARTIFACTORY_BUILD', value: ''),
string(name: 'TEST_CASE_DEBUG_INFORMATION', value: 'test:*'),
booleanParam(name: 'Skip Stage: Lint', value: true),
booleanParam(name: 'Skip Stage: Audit', value: true),
booleanParam(name: 'Skip Stage: SonarQube Scan', value: true)
],
propagate: false
)
echo "Test result: ${test_result.result}"
if (test_result.result != 'SUCCESS') {
testSmpeBuildErrorUrl = test_result.absoluteUrl
echo "Test failed on SMP/e build ${sourceSmpeBuildInfo.path}, check failure details at ${test_result.absoluteUrl}"
}
}
},
allowMissingJunit : true,
timeout: [time: 2, unit: 'HOURS']
)
pipeline.createStage(
name : "Promote",
isSkippable : true,
shouldExecute : {
return sourceSmpeBuildInfo && sourceSmpeBuildInfo['path'] &&
sourceSmpeReadmeInfo && sourceSmpeReadmeInfo['path'] &&
sourceRegBuildInfo && sourceRegBuildInfo['path'] &&
cliSourceBuildInfo && cliSourceBuildInfo['path']
},
stage : {
// promote Zowe nightly build
targetSmpeFullPath = pipeline.artifactory.promote([
'source' : sourceSmpeBuildInfo,
'targetPath' : "${ZOWE_RELEASE_REPOSITORY}${ZOWE_RELEASE_PATH}/"
])
targetSmpeReadmeFullPath = pipeline.artifactory.promote([
'source' : sourceSmpeReadmeInfo,
'targetPath' : "${ZOWE_RELEASE_REPOSITORY}${ZOWE_RELEASE_PATH}/"
])
targetRegFullPath = pipeline.artifactory.promote([
'source' : sourceRegBuildInfo,
'targetPath' : "${ZOWE_RELEASE_REPOSITORY}${ZOWE_RELEASE_PATH}/"
])
// promote Zowe CLI nightly build
cliTargetFullPath = pipeline.artifactory.promote([
'source' : cliSourceBuildInfo,
'targetPath' : "${ZOWE_RELEASE_REPOSITORY}${ZOWE_CLI_RELEASE_PATH}/"
])
},
timeout: [time: 10, unit: 'MINUTES']
)
pipeline.createStage(
name : "Message",
isSkippable : true,
stage : {
def slackColor = 'good'
def message = "Zowe Build ${ZOWE_BUILD_NAME}#${sourceRegBuildInfo['build.number']} is promoted as nightly build. You can download from:\n\n" +
"${lib.Constants.DEFAULT_ARTIFACTORY_URL}/${targetRegFullPath}\n\n" +
"${lib.Constants.DEFAULT_ARTIFACTORY_URL}/${targetSmpeFullPath}\n\n" +
"${lib.Constants.DEFAULT_ARTIFACTORY_URL}/${targetSmpeReadmeFullPath}\n\n" +
"The CLI Standalone Package ${ZOWE_CLI_BUILD_NAME}#${cliSourceBuildInfo['build.number']} is promoted as nightly CLI build. You can download from:\n\n" +
"${lib.Constants.DEFAULT_ARTIFACTORY_URL}/${cliTargetFullPath}"
if (testRegBuildErrorUrl) {
slackColor = 'warning'
message = message + "\n" +
"!!WARNING!! Smoke test FAILED on the regular build! Check test result here:\n\n" +
testRegBuildErrorUrl
}
if (testSmpeBuildErrorUrl) {
slackColor = 'warning'
message = message + "\n" +
"!!WARNING!! Smoke test FAILED on the SMP/e build! Check test result here:\n\n" +
testSmpeBuildErrorUrl
}
echo "*************************************************************************************************\n" +
message + "\n" +
"*************************************************************************************************"
def slackMessage = "${message}\nCheck pipeline detail: ${env.BUILD_URL}"
if (params.TEST_RUN) {
echo "Slack message in ${slackColor}:\n${slackMessage}"
} else {
slackSend channel: SLACK_CHANNEL,
color: slackColor,
message: slackMessage
}
},
timeout: [time: 2, unit: 'MINUTES']
)
pipeline.end()
}