-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathpr_test_pipeline.groovy
249 lines (221 loc) · 10.4 KB
/
pr_test_pipeline.groovy
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
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import groovy.json.JsonSlurper
import java.nio.file.NoSuchFileException
class PullRequestTestPipeline implements Serializable {
def context
def currentBuild
String branch
String gitRepo
Map<String, ?> testConfigurations
Map<String, ?> DEFAULTS_JSON
List<Integer> javaVersions
String BUILD_FOLDER = 'build-scripts-pr-tester/build-test'
String ADOPT_DEFAULTS_FILE_URL = 'https://raw.githubusercontent.com/adoptium/ci-jenkins-pipelines/master/pipelines/defaults.json'
def getAdopt = new URL(ADOPT_DEFAULTS_FILE_URL).openConnection()
Map<String, ?> ADOPT_DEFAULTS_JSON = new JsonSlurper().parseText(getAdopt.getInputStream().getText()) as Map
/*
* Creates a configuration for the top level pipeline job
*/
Map<String, ?> generateConfig(def javaVersion) {
return [
PR_BUILDER : true,
TEST : false,
GIT_URL : gitRepo,
BRANCH : branch,
BUILD_FOLDER : BUILD_FOLDER,
JAVA_VERSION : javaVersion,
JOB_NAME : "openjdk${javaVersion}-pipeline",
SCRIPT : "${DEFAULTS_JSON['scriptDirectories']['upstream']}/openjdk_pipeline.groovy",
disableJob : false,
pipelineSchedule : '0 0 31 2 0', // 31st Feb so will never run
targetConfigurations: testConfigurations,
defaultsJson : DEFAULTS_JSON,
adoptDefaultsJson : ADOPT_DEFAULTS_JSON,
CHECKOUT_CREDENTIALS: '',
adoptScripts : true,
enableTests : false,
enableReproducibleCompare : false,
enableTestDynamicParallel : false,
releaseType : "pr-tester"
]
}
/*
* Generates the top level pipeline job
*/
def generatePipelineJob(def javaVersion) {
context.println '[INFO] Running Pipeline Generation Script...'
Map<String, ?> config = generateConfig(javaVersion)
context.checkout([$class: 'GitSCM', userRemoteConfigs: [[url: config.GIT_URL]], branches: [[name: branch]]])
context.println "JDK${javaVersion} disableJob = ${config.disableJob}"
context.jobDsl targets: DEFAULTS_JSON['templateDirectories']['upstream'], ignoreExisting: false, additionalParameters: config
}
/*
* Main function, called from kick_off_tester.groovy by job "openjdk-build-pr-tester"
*/
def runTests() {
def jobs = [:]
Boolean pipelineFailed = false
// Load generation scripts
context.node('worker') {
context.println "loading ${context.WORKSPACE}/${DEFAULTS_JSON['scriptDirectories']['regeneration']}"
Closure regenerationScript = context.load "${context.WORKSPACE}/${DEFAULTS_JSON['scriptDirectories']['regeneration']}"
String actualJavaVersion = ""
javaVersions.each({ javaVersion ->
// generate top level job
generatePipelineJob(javaVersion)
context.println '[INFO] Running downstream jobs regeneration script...'
// Load platform specific build configs
def buildConfigurations
Boolean updateRepo = false
context.println "loading ${context.WORKSPACE}/${DEFAULTS_JSON['configDirectories']['build']}/jdk${javaVersion}_pipeline_config.groovy"
try {
buildConfigurations = context.load "${context.WORKSPACE}/${DEFAULTS_JSON['configDirectories']['build']}/jdk${javaVersion}_pipeline_config.groovy"
} catch (NoSuchFileException e) {
context.println "[WARNING] ${context.WORKSPACE}/${DEFAULTS_JSON['configDirectories']['build']}/jdk${javaVersion}_pipeline_config.groovy does not exist. Trying jdk${javaVersion}u_pipeline_config.groovy..."
buildConfigurations = context.load "${context.WORKSPACE}/${DEFAULTS_JSON['configDirectories']['build']}/jdk${javaVersion}u_pipeline_config.groovy"
updateRepo = true
}
actualJavaVersion = updateRepo ? "jdk${javaVersion}u" : "jdk${javaVersion}"
def excludedBuilds = ''
// Generate downstream build jobs
regenerationScript(
actualJavaVersion,
buildConfigurations,
testConfigurations,
DEFAULTS_JSON,
ADOPT_DEFAULTS_JSON,
excludedBuilds,
900,
currentBuild,
context,
'build-scripts-pr-tester/build-test',
[ url: gitRepo ],
branch,
DEFAULTS_JSON['templateDirectories']['downstream'],
DEFAULTS_JSON['baseFileDirectories']['downstream'],
DEFAULTS_JSON['scriptDirectories']['downstream'],
'https://ci.adoptium.net/job/build-scripts-pr-tester/job/build-test',
null,
null,
"pr-tester"
).regenerate()
context.println "[SUCCESS] Regeneration on ${javaVersion} all done!"
})
/*
Handling PR comments:
run tests run all version from $javaVersions
run tests quick run jdk17
run tests quick 8 run jdk8
run tests quick 11,17,21 run jdk11, 17, and 21
*/
String[] commentsList = context.params.ghprbCommentBody.trim().split('run tests quick')
switch (commentsList.size()) {
case 0:
javaVersions = [17]
break
case 1:
javaVersions = javaVersions
break
case 2:
javaVersions = commentsList[1].tokenize(',[]').collect { it as int }
break
}
// Calling build-test/openjdkX-pipeline against PR
javaVersions.each({ javaVersion ->
jobs["PR test JDK${javaVersion}"] = {
context.stage("Building pr-tester Java ${javaVersion}") {
try {
context.build job: "${BUILD_FOLDER}/openjdk${javaVersion}-pipeline",
propagate: true,
parameters: [
context.string(name: 'releaseType', value: 'Nightly Without Publish'),
context.string(name: 'activeNodeTimeout', value: '5'),
context.string(name: 'ciReference', value: "${branch}"), // use PR's SHA1 for the generated openjdkX-pipeline
context.booleanParam(name: 'enableTestDynamicParallel', value: false), // not needed unless we enable test
context.booleanParam(name: 'enableInstallers', value: false), // never need this enabled in pr-test
context.booleanParam(name: 'useAdoptBashScripts', value: false), // should not use defaultsJson but adoptDefaultsJson
context.booleanParam(name: 'keepReleaseLogs', value: false), // never need this enabled in pr-tester
context.booleanParam(name: 'cleanWorkspace', value: true), // always clean prtester workspace before the build
context.booleanParam(name: 'cleanWorkspaceAfterBuild', value: true) // always clean prtester workspace after the build
]
} catch (err) {
context.println "[ERROR] JDK ${actualJavaVersion} PIPELINE FAILED\n$err"
pipelineFailed = true
}
}
}
})
} // End: node("worker")
context.parallel jobs
// Move to "worker" workspace context to perform clean up...
context.node('worker') {
// Only clean up the space if the tester passed
if (!pipelineFailed) {
context.println '[INFO] Cleaning up...'
context.cleanWs notFailBuild: true
} else {
context.println '[ERROR] Pipelines failed. Setting build result to FAILURE...'
currentBuild.result = 'FAILURE'
}
}
}
}
Map<String, ?> defaultTestConfigurations = [
'x64Linux': [
'temurin'
],
'x64AlpineLinux' : [
'temurin'
],
'aarch64Linux': [
'temurin'
],
'x64Windows': [
'temurin'
],
'x64Mac': [
'temurin'
]
]
List<Integer> defaultJavaVersions = [8, 11, 17, 21]
return {
String branch,
def currentBuild,
def context,
String gitRepo,
Map<String, ?> DEFAULTS_JSON,
String testConfigurations = null,
String versions = null
->
Map<String, ?> testConfig = defaultTestConfigurations
List<Integer> javaVersions = defaultJavaVersions
Map<String, ?> defaultsJson = DEFAULTS_JSON
if (gitRepo == null) {
gitRepo = DEFAULTS_JSON['repository']['pipeline_url']
}
if (testConfigurations != null) {
testConfig = new JsonSlurper().parseText(testConfigurations) as Map
}
if (versions != null) {
javaVersions = new JsonSlurper().parseText(versions) as List<Integer>
}
return new PullRequestTestPipeline(
gitRepo: gitRepo,
branch: branch,
testConfigurations: testConfig,
DEFAULTS_JSON: defaultsJson,
javaVersions: javaVersions,
context: context,
currentBuild: currentBuild
)
}