-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
243 lines (225 loc) · 6.87 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
#!'groovy'
def projectName = env.JOB_NAME.substring(0, env.JOB_NAME.indexOf("/")) // depends on name and location of multibranch pipeline in jenkins
def jdk = 'openjdk-17'
def idea = '2021.2'
def ideaSHA256 = '7c27799861fb1ba0d43a3565a1ec2be789e1871191be709f0e79f1e17d3571fe'
def isRelease = env.BRANCH_NAME=="master"
def dockerNamePrefix = env.JOB_NAME.replace("/", "-").replace(" ", "_") + "-" + env.BUILD_NUMBER
def dockerDate = new Date().format("yyyyMMdd")
def ant = 'ant -noinput'
properties([
gitLabConnection(env.GITLAB_CONNECTION),
buildDiscarder(logRotator(
numToKeepStr : isRelease ? '1000' : '30',
artifactNumToKeepStr : isRelease ? '100' : '2'
))
])
tryCompleted = false
try
{
def parallelBranches = [:]
parallelBranches["Main"] =
{
//noinspection GroovyAssignabilityCheck
nodeCheckoutAndDelete
{
scmResult ->
def buildTag = makeBuildTag(scmResult)
def dockerName = dockerNamePrefix + "-Main"
def mainImage = docker.build(
'exedio-jenkins:' + dockerName + '-' + dockerDate,
'--build-arg JDK=' + jdk + ' ' +
'--build-arg JENKINS_OWNER=' + env.JENKINS_OWNER + ' ' +
'conf/main')
mainImage.inside(
"--name '" + dockerName + "' " +
"--cap-drop all " +
"--security-opt no-new-privileges " +
"--network none")
{
shSilent ant + " clean jenkins" +
' "-Dbuild.revision=${BUILD_NUMBER}"' +
' "-Dbuild.tag=' + buildTag + '"' +
' -Dbuild.status=' + (isRelease?'release':'integration') +
' -Dtomcat.port.shutdown=18005' +
' -Dtomcat.port.http=18080' +
' -Dtomcat.port.https=18443'
}
recordIssues(
failOnError: true,
enabledForFailure: true,
ignoreFailedBuilds: false,
qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]],
tools: [
java(),
],
skipPublishingChecks: true,
)
junit(
allowEmptyResults: false,
testResults: 'build/testresults/*.xml',
skipPublishingChecks: true
)
archiveArtifacts 'build/catalina-start.log'
archiveArtifacts fingerprint: true, artifacts: 'build/success/*'
plot(
csvFileName: 'plots.csv',
exclZero: false,
keepRecords: false,
group: 'Sizes',
title: 'exedio-cops.jar',
numBuilds: '150',
style: 'line',
useDescr: false,
propertiesSeries: [
[ file: 'build/exedio-cops.jar-plot.properties', label: 'exedio-cops.jar' ],
[ file: 'build/exedio-cops-src.zip-plot.properties', label: 'exedio-cops-src.zip' ],
],
)
}
}
parallelBranches["Idea"] =
{
//noinspection GroovyAssignabilityCheck
nodeCheckoutAndDelete
{
recordIssues(
failOnError: true,
enabledForFailure: true,
ignoreFailedBuilds: false,
qualityGates: [[threshold: 1, type: 'TOTAL_HIGH', unstable: true]],
tools: [
taskScanner(
excludePattern:
'.git/**,lib/**,' +
'testsrc/com/exedio/cops/ResourceTest.bin,' +
'**/*.jar,**/*.zip,**/*.tgz,**/*.jpg,**/*.gif,**/*.png,**/*.tif,**/*.webp,**/*.pdf,**/*.eot,**/*.ttf,**/*.woff,**/*.woff2,**/keystore', // binary file types
highTags: 'FIX' + 'ME', // causes build to become unstable, concatenation prevents matching this line
normalTags: 'TODO', // does not cause build to become unstable
ignoreCase: true),
],
)
def dockerName = dockerNamePrefix + "-Idea"
docker.
build(
'exedio-jenkins:' + dockerName + '-' + dockerDate,
'--build-arg JDK=' + jdk + ' ' +
'--build-arg IDEA=' + idea + ' ' +
'--build-arg IDEA_SHA256=' + ideaSHA256 + ' ' +
'conf/idea').
inside(
"--name '" + dockerName + "' " +
"--cap-drop all " +
"--security-opt no-new-privileges " +
"--network none")
{
shSilent ant + " src"
shSilent "/opt/idea/bin/inspect.sh " + env.WORKSPACE + " 'Project Default' idea-inspection-output"
}
archiveArtifacts 'idea-inspection-output/**'
shSilent "rm idea-inspection-output/GrazieInspection.xml" // grammar and style; settings/exclusions are stored in IDE and not in project
// 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(
failOnError: true,
enabledForFailure: true,
ignoreFailedBuilds: false,
qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]],
tools: [
ideaInspection(pattern: 'idea-inspection-output/**'),
],
)
}
}
parallelBranches["Ivy"] =
{
def cache = 'jenkins-build-survivor-' + projectName + "-Ivy"
//noinspection GroovyAssignabilityCheck
lockNodeCheckoutAndDelete(cache)
{
def dockerName = dockerNamePrefix + "-Ivy"
def mainImage = docker.build(
'exedio-jenkins:' + dockerName + '-' + dockerDate,
'--build-arg JDK=' + jdk + ' ' +
'--build-arg JENKINS_OWNER=' + env.JENKINS_OWNER + ' ' +
'conf/main')
mainImage.inside(
"--name '" + dockerName + "' " +
"--cap-drop all " +
"--security-opt no-new-privileges " +
"--mount type=volume,src=" + cache + ",target=/var/jenkins-build-survivor")
{
shSilent ant +
" -buildfile ivy" +
" -Divy.user.home=/var/jenkins-build-survivor"
}
archiveArtifacts 'ivy/artifacts/report/**'
def gitStatus = sh (script: "git status --porcelain --untracked-files=normal", returnStdout: true).trim()
if(gitStatus!='')
{
error 'FAILURE because fetching dependencies produces git diff:\n' + gitStatus
}
}
}
parallel parallelBranches
tryCompleted = true
}
finally
{
if(!tryCompleted)
currentBuild.result = 'FAILURE'
node('email')
{
step([$class: 'Mailer',
recipients: emailextrecipients([isRelease ? culprits() : developers(), requestor()]),
notifyEveryUnstableBuild: true])
}
updateGitlabCommitStatus state: currentBuild.resultIsBetterOrEqualTo("SUCCESS") ? "success" : "failed" // https://docs.gitlab.com/ee/api/commits.html#post-the-build-status-to-a-commit
}
def lockNodeCheckoutAndDelete(resource, Closure body)
{
lock(resource)
{
nodeCheckoutAndDelete(body)
}
}
def nodeCheckoutAndDelete(Closure body)
{
node('GitCloneExedio && docker')
{
env.JENKINS_OWNER =
sh (script: "id --user", returnStdout: true).trim() + ':' +
sh (script: "id --group", returnStdout: true).trim()
try
{
deleteDir()
def scmResult = checkout scm
updateGitlabCommitStatus state: 'running'
body.call(scmResult)
}
finally
{
deleteDir()
}
}
}
def makeBuildTag(scmResult)
{
return 'build ' +
env.BRANCH_NAME + ' ' +
env.BUILD_NUMBER + ' ' +
new Date().format("yyyy-MM-dd") + ' ' +
scmResult.GIT_COMMIT + ' ' +
sh (script: "git cat-file -p " + scmResult.GIT_COMMIT + " | grep '^tree ' | sed -e 's/^tree //'", returnStdout: true).trim()
}
def shSilent(script)
{
try
{
sh script
}
catch(Exception ignored)
{
currentBuild.result = 'FAILURE'
}
}