-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
openjdk_pipeline.groovy
284 lines (251 loc) · 12.7 KB
/
openjdk_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
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
import groovy.json.JsonSlurper
import java.nio.file.NoSuchFileException
/*
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.
*/
def javaToBuild = "jdk${params.jdkVersion}"
def scmVars = null
Closure configureBuild = null
def buildConfigurations = null
Map<String, ?> DEFAULTS_JSON = null
// Find the testenv ga commit SHA specified by the jdkBranch
// Returns a Tuple2 of "repository", "gaCommitSHA"
def findGaCommitSHA(String jdkVersion, String jdkBranch, Boolean annotatedTag) {
// Determine OpenJDK and Adoptium mirror repository
def repo
// Is it a jdk-23+ stablizationjdk branch version? ie.jdk-23, jdk-24, ...
if (jdkVersion.toInteger() >= 23 && !jdkBranch.contains(".0")) {
// jdk-23+ first release is a branch within the jdk(head) repository
repo = "jdk"
} else {
if (jdkBranch.contains("jdk8u") && jdkBranch.contains("aarch32")) {
repo = "aarch32-port-jdk8u"
} else {
repo = "jdk${jdkVersion}"
}
}
def openjdkRepo = "https://github.com/openjdk/${repo}"
def adoptiumRepo = "https://github.com/adoptium/${repo}"
if (annotatedTag) {
println "Searching for Annotated git tag with name '${jdkBranch}' using repo base: ${openjdkRepo}"
} else {
println "Searching for Lightweight git tag with name '${jdkBranch}' using repo base: ${openjdkRepo}"
}
// Annotated tags are refs with suffix ^{}
def annotatedTagFilter = (annotatedTag ? "| grep '\\^{}'" : "| grep -v '\\^{}'")
def searchRepo = "${openjdkRepo}"
def gaCommitSHA = sh(returnStdout: true, script:"git ls-remote --tags ${searchRepo} ${annotatedTagFilter} | grep \"${jdkBranch}\" | tr -s '\\t ' ' ' | cut -d' ' -f1 | tr -d '\\n'")
if (gaCommitSHA == "") {
// Try "updates" repo..
searchRepo = "${openjdkRepo}u"
gaCommitSHA = sh(returnStdout: true, script:"git ls-remote --tags ${searchRepo} ${annotatedTagFilter} | grep \"${jdkBranch}\" | tr -s '\\t ' ' ' | cut -d' ' -f1 | tr -d '\\n'")
}
if (gaCommitSHA == "") {
// Maybe an Adoptium "dryrun" try Adoptium mirror repo..
searchRepo = "${adoptiumRepo}"
gaCommitSHA = sh(returnStdout: true, script:"git ls-remote --tags ${searchRepo} ${annotatedTagFilter} | grep \"${jdkBranch}\" | tr -s '\\t ' ' ' | cut -d' ' -f1 | tr -d '\\n'")
}
if (gaCommitSHA == "") {
// Maybe an Adoptium "dryrun" try Adoptium mirror "updates" repo..
searchRepo = "${adoptiumRepo}u"
gaCommitSHA = sh(returnStdout: true, script:"git ls-remote --tags ${searchRepo} ${annotatedTagFilter} | grep \"${jdkBranch}\" | tr -s '\\t ' ' ' | cut -d' ' -f1 | tr -d '\\n'")
}
if (gaCommitSHA != "") {
return new Tuple2(searchRepo, gaCommitSHA)
} else {
return null
}
}
// Resolve a "-ga" tag to the actual upstream openjdk build tag of the same commit
// Also check adoptium mirror for "dryrun" tags
def resolveGaTag(String jdkVersion, String jdkBranch) {
def resolvedTag = jdkBranch // Default to as-is
Boolean annotatedTag = true
def resolveGaCommit = findGaCommitSHA(jdkVersion, jdkBranch, annotatedTag)
if (resolveGaCommit == null) {
// Try searching for a lightweight tag
annotatedTag = false
resolveGaCommit = findGaCommitSHA(jdkVersion, jdkBranch, annotatedTag)
}
if (resolveGaCommit == null) {
println "[ERROR] Unable to resolve ${jdkBranch} upstream commit, will try to match tag as-is"
} else {
// Annotated tags are refs with suffix ^{}
def annotatedTagFilter = (annotatedTag ? "| grep '\\^{}'" : "| grep -v '\\^{}'")
def foundRepo = resolveGaCommit.get(0)
def foundSHA = resolveGaCommit.get(1)
def upstreamTag = sh(returnStdout: true, script:"git ls-remote --tags ${foundRepo} ${annotatedTagFilter} | grep \"${foundSHA}\" | grep -v \"${jdkBranch}\" | tr -s '\\t ' ' ' | cut -d' ' -f2 | sed \"s,refs/tags/,,\" | sed \"s,\\^{},,\" | tr -d '\\n'")
if (upstreamTag != "") {
println "[INFO] Resolved ${jdkBranch} to upstream build tag ${upstreamTag}"
resolvedTag = upstreamTag
} else {
println "[ERROR] Unable to resolve ${jdkBranch} upstream commit, will try to match tag as-is"
}
}
return resolvedTag
}
node('worker') {
// Ensure workspace is clean so we don't archive any old failed pipeline artifacts
println '[INFO] Cleaning up controller worker workspace prior to running pipelines..'
// Fail if unable to clean..
cleanWs notFailBuild: false
if (params.releaseType == 'Release' && params.aqaReference != '' && params.scmReference != '') {
def propertyFile = 'testenv.properties'
if (params.jdkVersion == '8' && params.targetConfigurations.contains('arm32Linux')) {
propertyFile = 'testenv_arm32.properties'
}
if ( ! ( "${params.aqareference}" ==~ /^[A-Za-z0-9\/\.\-_]*$/ ) ) {
throw new Exception("[ERROR] Dubious characters in aqa reference - aborting");
}
sh("curl -Os https://raw.githubusercontent.com/adoptium/aqa-tests/${params.aqaReference}/testenv/${propertyFile}")
def buildTag = params.scmReference
if (params.scmReference.contains('_adopt')) {
buildTag = params.scmReference.substring(0, params.scmReference.length() - 6) // remove _adopt suffix
}
def list = readFile("${propertyFile}").readLines()
def jdkBranch = ""
def jdkOpenj9Branch = ""
for (item in list) {
if (item.contains("JDK${params.jdkVersion}_BRANCH")) {
def branchInfo = item.split('=')
jdkBranch = branchInfo[1]
} else if (item.contains("JDK${params.jdkVersion}_OPENJ9_BRANCH")) {
def branchInfo = item.split('=')
jdkOpenj9Branch = branchInfo[1]
}
if (jdkBranch && jdkOpenj9Branch) {
break
}
}
// If testenv tag is a "-ga" tag, then resolve to the actual openjdk build tag it's tagging
if (jdkBranch.contains("-ga")) {
jdkBranch = resolveGaTag("${params.jdkVersion}", jdkBranch)
}
if (jdkBranch == buildTag || jdkBranch == params.scmReference) {
println "[INFO] scmReference=${buildTag} matches with JDK${params.jdkVersion}_BRANCH=${jdkBranch} in ${propertyFile} in aqa-tests release branch."
} else if (jdkOpenj9Branch == buildTag) {
println "[INFO] scmReference=${buildTag} matches with JDK${params.jdkVersion}_OPENJ9_BRANCH=${jdkOpenj9Branch} in ${propertyFile} in aqa-tests release branch."
} else {
println "[ERROR] scmReference does not match with any JDK branch in ${propertyFile} in aqa-tests release branch. Please update aqa-tests ${params.aqaReference} release branch. Set the current build result to FAILURE!"
currentBuild.result = 'FAILURE'
return
}
}
// Load defaultsJson. These are passed down from the build_pipeline_generator and is a JSON object containing user's default constants.
if (!params.defaultsJson || defaultsJson == '') {
throw new Exception('[ERROR] No User Defaults JSON found! Please ensure the defaultsJson parameter is populated and not altered during parameter declaration.')
} else {
DEFAULTS_JSON = new JsonSlurper().parseText(defaultsJson) as Map
}
// Load adoptDefaultsJson. These are passed down from the build_pipeline_generator and is a JSON object containing adopt's default constants.
if (!params.adoptDefaultsJson || adoptDefaultsJson == '') {
throw new Exception('[ERROR] No Adopt Defaults JSON found! Please ensure the adoptDefaultsJson parameter is populated and not altered during parameter declaration.')
} else {
ADOPT_DEFAULTS_JSON = new JsonSlurper().parseText(adoptDefaultsJson) as Map
}
/*
Changes dir to Adopt's pipeline repo. Use closures as functions aren't accepted inside node blocks
*/
def checkoutAdoptPipelines = { ->
checkout([$class: 'GitSCM',
branches: [ [ name: ADOPT_DEFAULTS_JSON['repository']['pipeline_branch'] ] ],
userRemoteConfigs: [ [ url: ADOPT_DEFAULTS_JSON['repository']['pipeline_url'] ] ]
])
}
scmVars = checkout scm
String helperRef = DEFAULTS_JSON['repository']['helper_ref']
library(identifier: "openjdk-jenkins-helper@${helperRef}")
// Load baseFilePath. This is where build_base_file.groovy is located. It runs the downstream job setup and configuration retrieval services.
def baseFilePath = (params.baseFilePath) ?: DEFAULTS_JSON['baseFileDirectories']['upstream']
try {
configureBuild = load "${WORKSPACE}/${baseFilePath}"
} catch (NoSuchFileException e) {
println "[WARNING] ${baseFilePath} does not exist in your repository. Attempting to pull Adopt's base file script instead."
checkoutAdoptPipelines()
configureBuild = load "${WORKSPACE}/${ADOPT_DEFAULTS_JSON['baseFileDirectories']['upstream']}"
checkout scm
}
// Load buildConfigFilePath. This is where jdkxx_pipeline_config.groovy is located. It contains the build configurations for each platform, architecture and variant.
def buildConfigFilePath = (params.buildConfigFilePath) ?: "${DEFAULTS_JSON['configDirectories']['build']}/${javaToBuild}u_pipeline_config.groovy"
// Check if pipeline is jdk11 or jdk11u
def configPath = "${WORKSPACE}/${buildConfigFilePath}"
if (fileExists(configPath)) {
javaToBuild = (params.buildConfigFilePath) ? "${javaToBuild}" : "${javaToBuild}u"
println "Found ${buildConfigFilePath}"
} else {
buildConfigFilePath = (params.buildConfigFilePath) ?: "${DEFAULTS_JSON['configDirectories']['build']}/${javaToBuild}_pipeline_config.groovy"
}
try {
buildConfigurations = load "${WORKSPACE}/${buildConfigFilePath}"
} catch (NoSuchFileException e) {
println "[WARNING] ${buildConfigFilePath} does not exist in your repository. Attempting to pull Adopt's build configs instead."
checkoutAdoptPipelines()
// Reset javaToBuild to original value before trying again. Converts 11u to 11
javaToBuild = javaToBuild.replaceAll('u', '')
// Check if pipeline is jdk11 or jdk11u
configPath = "${WORKSPACE}/${ADOPT_DEFAULTS_JSON['configDirectories']['build']}/${javaToBuild}u_pipeline_config.groovy"
if (fileExists(configPath)) {
javaToBuild = "${javaToBuild}u"
buildConfigurations = load "${WORKSPACE}/${ADOPT_DEFAULTS_JSON['configDirectories']['build']}/${javaToBuild}_pipeline_config.groovy"
} else {
buildConfigurations = load "${WORKSPACE}/${ADOPT_DEFAULTS_JSON['configDirectories']['build']}/${javaToBuild}_pipeline_config.groovy"
}
checkout scm
}
}
// If a parameter below hasn't been declared above, it is declared in the jenkins job itself
if (scmVars != null || configureBuild != null || buildConfigurations != null) {
try {
configureBuild(
javaToBuild,
buildConfigurations,
targetConfigurations,
DEFAULTS_JSON,
activeNodeTimeout,
dockerExcludes,
enableReproducibleCompare,
enableTests,
enableTestDynamicParallel,
enableInstallers,
enableSigner,
releaseType,
scmReference,
buildReference,
ciReference,
helperReference,
aqaReference,
aqaAutoGen,
overridePublishName,
useAdoptBashScripts,
additionalConfigureArgs,
scmVars,
additionalBuildArgs,
overrideFileNameVersion,
cleanWorkspaceBeforeBuild,
cleanWorkspaceAfterBuild,
cleanWorkspaceBuildOutputAfterBuild,
adoptBuildNumber,
propagateFailures,
keepTestReportDir,
keepReleaseLogs,
currentBuild,
this,
env
).doBuild()
} finally {
node('worker') {
println '[INFO] Cleaning up controller worker workspace...'
cleanWs notFailBuild: true
}
}
} else {
throw new Exception("[ERROR] One or more setup parameters are null.\nscmVars = ${scmVars}\nconfigureBuild = ${configureBuild}\nbuildConfigurations = ${buildConfigurations}")
}