-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
340 lines (304 loc) · 9.77 KB
/
Jenkinsfile
File metadata and controls
340 lines (304 loc) · 9.77 KB
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'
import groovy.transform.Field
import groovy.transform.stc.ClosureParams
import groovy.transform.stc.SimpleType
@Field
String projectNamePattern = "^exedio/([0-9a-z]*)/.*" // depends on location of multibranch pipeline in jenkins
@Field
String debianRelease = 'bullseye'
@Field
String debianSnapshot = '20240904'
@Field
String jdk = 'openjdk-17'
@Field
String idea = '2025.3.3-PATCHED'
@Field
String ideaSHA256 = '38a4392fe2117185c3991d9bc8dd83bacdcfa0e1e223ce33c082cbef618d99a9'
boolean isRelease = env.BRANCH_NAME=="master" || env.BRANCH_NAME=="main"
Map<String, ?> recordIssuesDefaults = [
failOnError : true,
enabledForFailure : true,
ignoreFailedBuilds : false,
skipPublishingChecks: true,
qualityGates : [[threshold: 1, type: 'TOTAL', unstable: true]],
]
properties([
gitLabConnection(env.GITLAB_CONNECTION),
buildDiscarder(
logRotator(
numToKeepStr : isRelease ? '1000' : '30',
artifactNumToKeepStr : isRelease ? '100' : '2',
))
])
boolean tryCompleted = false
try
{
Map<String, Closure<?>> parallelBranches = [:]
parallelBranches["Main"] = {
nodeCheckoutAndDelete { scmResult ->
def buildTag = makeBuildTag(scmResult)
mainImage(imageName("Main")).inside(dockerRunDefaults()) {
ant 'clean jenkins' +
' "-Dbuild.revision=${BUILD_NUMBER}"' +
' "-Dbuild.tag=' + buildTag + '"' +
' -Dbuild.status=' + (isRelease?'release':'integration') +
' -Dinstrument.verify=true' +
' -Ddisable-ansi-colors=true'
}
recordIssues(
*: recordIssuesDefaults,
tools: [
java(),
],
)
junit(
allowEmptyResults: false,
testResults: 'build/testresults/*.xml',
skipPublishingChecks: true
)
archiveArtifacts fingerprint: true, artifacts: 'build/success/*'
plot(
csvFileName: 'plots.csv',
exclZero: false,
keepRecords: false,
group: 'Sizes',
title: 'exedio-cope-im4java.jar',
numBuilds: '150',
style: 'line',
useDescr: false,
propertiesSeries: [
[ file: 'build/exedio-cope-im4java.jar-plot.properties', label: 'exedio-cope-im4java.jar' ],
[ file: 'build/exedio-cope-im4java-src.zip-plot.properties', label: 'exedio-cope-im4java-src.zip' ],
],
)
}
}
parallelBranches["Github"] = {
nodeCheckoutAndDelete {
def mainImage = docker.build(
imageName('Github'),
'--build-arg DEBIAN_RELEASE=' + debianRelease + ' ' +
'--build-arg DEBIAN_SNAPSHOT=' + debianSnapshot + ' ' +
'--build-arg JDK=' + jdk + ' ' +
'conf/github')
mainImage.inside(dockerRunDefaults()) {
// corresponds to .github/workflows/ant.yml
ant '-Dgithub=true clean jenkins'
}
junit(
allowEmptyResults: false,
testResults: 'build/testresults/*.xml',
skipPublishingChecks: true
)
}
}
parallelBranches["Forensic"] = {
nodeCheckoutAndDelete {
discoverGitReferenceBuild()
gitDiffStat()
if (isRelease || env.BRANCH_NAME.contains("forensic")) mineRepository()
recordIssues(
*: recordIssuesDefaults,
qualityGates: [[threshold: 1, type: 'TOTAL_HIGH', unstable: true]],
tools: [
taskScanner(
excludePattern:
'.git/**,lib/**,' +
// binary file types
'**/*.jar,**/*.zip,**/*.tgz,**/*.jpg,**/*.gif,**/*.png,**/*.tif,**/*.webp,**/*.pdf,**/*.eot,**/*.ttf,**/*.woff,**/*.woff2,**/keystore',
// causes build to become unstable, concatenation prevents matching this line
highTags: 'FIX' + 'ME',
// does not cause build to become unstable
normalTags: 'TODO',
ignoreCase: true),
],
)
}
}
parallelBranches["Idea"] = {
nodeCheckoutAndDelete {
def ideaImage = docker.build(
imageName('Idea'),
'--build-arg DEBIAN_RELEASE=' + debianRelease + ' ' +
'--build-arg DEBIAN_SNAPSHOT=' + debianSnapshot + ' ' +
'--build-arg JDK=' + jdk + ' ' +
'--build-arg IDEA=' + idea + ' ' +
'--build-arg IDEA_SHA256=' + ideaSHA256 + ' ' +
'conf/idea')
ideaImage.inside(dockerRunDefaults()) {
shSilent "/opt/idea/bin/inspect.sh " + env.WORKSPACE + " 'Project Default' idea-inspection-output"
shSilent 'cp /tmp/idea/.cache/JetBrains/*/log/idea.log .'
}
archiveArtifacts 'idea-inspection-output/**,idea.log'
shSilent "rm idea-inspection-output/GrazieInspection.xml" // Grammar
shSilent "rm idea-inspection-output/SpellCheckingInspection.xml"
// replace project dir to prevent UnsupportedOperationException - will not be exposed in artifacts
shSilent "find idea-inspection-output -name '*.xml' | " +
"xargs --no-run-if-empty sed --in-place -- 's=\\\$PROJECT_DIR\\\$=" + env.WORKSPACE + "=g'"
recordIssues(
*: recordIssuesDefaults,
tools: [ideaInspection(pattern: 'idea-inspection-output/**')],
)
}
}
parallelBranches["Ivy"] = {
def cache = 'jenkins-build-survivor-' + projectName() + "-Ivy"
lockNodeCheckoutAndDelete(cache, "jenkins-build-survivor") {
mainImage(imageName('Ivy')).inside(
dockerRunDefaults('bridge') +
"--mount type=volume,src=" + cache + ",target=/var/jenkins-build-survivor") {
ant "-buildfile ivy" +
" -Divy.user.home=/var/jenkins-build-survivor"
}
archiveArtifacts 'ivy/artifacts/report/**'
// There should be an assertIvyExtends for each <conf name="abc" extends="def" /> in ivy/ivy.xml.
assertIvyExtends("build", "runtime")
}
}
parallel parallelBranches
tryCompleted = true
}
finally
{
if (!tryCompleted)
currentBuild.result = 'FAILURE'
// workaround for Mailer plugin: set result status explicitly to SUCCESS if empty, otherwise no mail will be triggered if a build gets successful after a previous unsuccessful build
if (currentBuild.result == null)
currentBuild.result = 'SUCCESS'
node('email') {
step(
[$class : 'Mailer',
recipients : emailextrecipients([isRelease ? culprits() : developers(), requestor()]),
notifyEveryUnstableBuild: true])
}
// https://docs.gitlab.com/ee/api/commits.html#post-the-build-status-to-a-commit
updateGitlabCommitStatus state: currentBuild.resultIsBetterOrEqualTo("SUCCESS") ? "success" : "failed"
}
// ------------------- LIBRARY ----------------------------
// The code below is meant to be equal across all projects.
String projectName()
{
String jobName = env.JOB_NAME
java.util.regex.Matcher m = java.util.regex.Pattern.compile(projectNamePattern).
matcher(jobName)
if(!m.matches())
error "illegal jobName >" + jobName + "<, must match " + projectNamePattern
String result = m.group(1)
echo("project name >" + result + "< computed from >" + jobName + "<")
return result
}
void lockNodeCheckoutAndDelete(String resource, String additionalLabel = '', Closure body)
{
lock(resource) {
nodeCheckoutAndDelete(additionalLabel, body)
}
}
void nodeCheckoutAndDelete(
String additionalLabel = '',
@ClosureParams(value = SimpleType, options = ["Map<String, String>"]) Closure body)
{
node('GitCloneExedio && docker' + (additionalLabel.isEmpty() ? '' : " && " + additionalLabel)) {
env.JENKINS_OWNER = shStdout("id --user") + ':' + shStdout("id --group")
try
{
deleteDir()
def scmResult = checkout scm
updateGitlabCommitStatus state: 'running'
body.call(scmResult)
assertGitUnchanged()
}
finally
{
deleteDir()
}
}
}
String jobNameAndBuildNumber()
{
env.JOB_NAME.replace("/", "-").replace(" ", "_") + "-" + env.BUILD_NUMBER
}
def mainImage(String imageName)
{
return docker.build(
imageName,
'--build-arg DEBIAN_RELEASE=' + debianRelease + ' ' +
'--build-arg DEBIAN_SNAPSHOT=' + debianSnapshot + ' ' +
'--build-arg JDK=' + jdk + ' ' +
'--build-arg JENKINS_OWNER=' + env.JENKINS_OWNER + ' ' +
'conf/main')
}
String imageName(String pipelineBranch, String subImage = '')
{
String isoToday = new Date().format("yyyyMMdd")
String name = 'exedio-jenkins:' + jobNameAndBuildNumber() + '-' + pipelineBranch + '-' + isoToday
if (!subImage.isEmpty()) name += '-' + subImage
return name
}
static String dockerRunDefaults(String network = 'none', String hostname = '')
{
return "--cap-drop all " +
"--security-opt no-new-privileges " +
"--network " + network + " " +
(hostname != '' ? "--network-alias " + hostname + " " : "") +
"--dns-opt timeout:1 " + // seconds; default is 5
"--dns-opt attempts:1 " // default is 2
}
String makeBuildTag(Map<String, String> scmResult)
{
String treeHash = shStdout "git cat-file -p " + scmResult.GIT_COMMIT + " | grep '^tree ' | sed -e 's/^tree //'"
return 'build ' +
env.BRANCH_NAME + ' ' +
env.BUILD_NUMBER + ' ' +
new Date().format("yyyy-MM-dd") + ' ' +
scmResult.GIT_COMMIT + ' ' +
treeHash
}
void assertIvyExtends(String extendingConf, String parentConf)
{
int status = shStatus(
"LC_ALL=C" +
" diff --recursive lib/" + parentConf + " lib/" + extendingConf +
" | grep --invert-match '^Only in lib/" + extendingConf + ": '" +
" > ivy/artifacts/ivyExtends" + extendingConf + ".txt")
if (status!=0 && status!=1) // https://www.man7.org/linux/man-pages/man1/diff.1.html
{
error 'FAILURE because diff had trouble'
}
String result = readFile "ivy/artifacts/ivyExtends" + extendingConf + ".txt"
if (result != '')
{
error 'FAILURE because ivy conf "' + extendingConf + '" does not just add jar-files to "' + parentConf + '":\n' +
result
}
}
void shSilent(String script)
{
try
{
sh script
}
catch (Exception ignored)
{
currentBuild.result = 'FAILURE'
}
}
int shStatus(String script)
{
return (int) sh(script: script, returnStatus: true)
}
String shStdout(String script)
{
return ((String) sh(script: script, returnStdout: true)).trim()
}
void ant(String script)
{
shSilent 'ant -noinput ' + script
}
void assertGitUnchanged()
{
String gitStatus = shStdout "git -c core.excludesFile=.gitignore-jenkins status --porcelain --untracked-files=normal"
if (gitStatus != '')
{
error 'FAILURE because build produces git diff:\n' + gitStatus
}
}