forked from infinispan/infinispan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
259 lines (228 loc) · 11.6 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/usr/bin/env groovy
pipeline {
agent {
label 'slave-group-normal || slave-group-k8s'
}
environment {
TOKEN = credentials('jira-infinspan-bot')
}
parameters {
choice(name: 'TEST_JDK', choices: ['Default', 'JDK 17', 'JDK 21', 'JDK latest'], description: 'The JDK used to run tests')
}
options {
timeout(time: 3, unit: 'HOURS')
timestamps()
buildDiscarder(logRotator(numToKeepStr: '100', daysToKeepStr: '61'))
}
stages {
stage('Prepare') {
steps {
script {
env.MAVEN_HOME = tool('Maven')
env.MAVEN_OPTS = "-Xmx1500m -XX:+HeapDumpOnOutOfMemoryError"
env.JAVA_HOME = tool('JDK 21')
env.GRAALVM_HOME = tool('GraalVM 21')
if (params.TEST_JDK != 'Default') {
env.JAVA_ALT_HOME = tool(params.TEST_JDK)
env.ALT_TEST_BUILD = "-Pjava-alt-test"
} else {
env.ALT_TEST_BUILD = ""
}
// ISPN-9703 Ensure distribution build works on non-prs
env.DISTRIBUTION_BUILD = !env.BRANCH_NAME.startsWith('PR-') || pullRequest.labels.contains('Documentation') || pullRequest.labels.contains('Image Required') ? "-Pdistribution" : ""
// Collect reports on non-prs
env.REPORTS_BUILD = env.BRANCH_NAME.startsWith('PR-') ? "" : "surefire-report:report pmd:cpd pmd:pmd spotbugs:spotbugs"
}
echo "-----------"
echo env.NODE_NAME
echo "-----------"
sh "$JAVA_HOME/bin/java --version"
echo "-----------"
sh "$MAVEN_HOME/bin/mvn --version"
echo "-----------"
sh "$GRAALVM_HOME/bin/java --version"
echo "-----------"
sh 'cleanup.sh'
}
}
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
sh "$MAVEN_HOME/bin/mvn clean install $REPORTS_BUILD -B -e -DskipTests -Pnative $DISTRIBUTION_BUILD"
}
}
stage('Image') {
when {
expression {
return !env.BRANCH_NAME.startsWith("PR-") || pullRequest.labels.contains('Image Required')
}
}
steps {
script {
def mvnCmd = '-q -Dexec.executable=echo -Dexec.args=\'${project.version}\' --non-recursive exec:exec'
def SERVER_VERSION = sh(
script: "${MAVEN_HOME}/bin/mvn ${mvnCmd}",
returnStdout: true
).trim()
def REPO = 'quay.io/infinispan-test/server'
def TAG = env.BRANCH_NAME
def IMAGE_BRANCH = env.CHANGE_ID ? pullRequest.base : env.BRANCH_NAME
sh "rm -rf infinispan-images"
sh "git clone --single-branch --branch ${IMAGE_BRANCH} --depth 1 https://github.com/infinispan/infinispan-images.git"
dir('infinispan-images') {
sh "cekit -v --descriptor server-openjdk.yaml build --overrides '{\"name\":\"${REPO}\", \"version\":\"${TAG}\"}' --overrides '{\"artifacts\":[{\"name\":\"server\",\"path\":\"../distribution/target/distribution/infinispan-server-${SERVER_VERSION}.zip\"}]}' docker\n"
withDockerRegistry(credentialsId: 'Quay-InfinispanTest', url: 'https://quay.io') {
sh "docker push ${REPO}:${TAG}"
}
sh "docker rmi ${REPO}:${TAG}"
deleteDir()
}
// CHANGE_ID is set only for pull requests, so it is safe to access the pullRequest global variable
if (env.CHANGE_ID) {
pullRequest.comment("Image pushed for Jenkins build [#${env.BUILD_NUMBER}](${env.BUILD_URL}):\n```\n${REPO}:${TAG}\n```")
}
}
}
}
stage('Native Image') {
when {
expression {
return !env.BRANCH_NAME.startsWith("PR-") || pullRequest.labels.contains('Native Image Required')
}
}
steps {
script {
def mvnCmd = '-q -Dexec.executable=echo -Dexec.args=\'${project.version}\' --non-recursive exec:exec'
def SERVER_VERSION = sh(
script: "${MAVEN_HOME}/bin/mvn ${mvnCmd}",
returnStdout: true
).trim()
def REPO = 'quay.io/infinispan-test/server-native'
def TAG = env.BRANCH_NAME
def IMAGE_BRANCH = env.CHANGE_ID ? pullRequest.base : env.BRANCH_NAME
sh "rm -rf infinispan-images"
sh "git clone --single-branch --branch ${IMAGE_BRANCH} --depth 1 https://github.com/infinispan/infinispan-images.git"
dir('infinispan-images') {
sh "cekit -v --descriptor server-dev-native.yaml build --overrides '{\"name\":\"${REPO}\", \"version\":\"${TAG}\"}' --overrides '{\"artifacts\":[{\"name\":\"server\",\"path\":\"../quarkus/server-runner/target/infinispan-quarkus-server-runner-${SERVER_VERSION}-runner\"},{\"name\":\"cli\",\"path\":\"../quarkus/cli/target/infinispan-cli\"}]}' docker\n"
withDockerRegistry(credentialsId: 'Quay-InfinispanTest', url: 'https://quay.io') {
sh "docker push ${REPO}:${TAG}"
}
sh "docker rmi ${REPO}:${TAG}"
deleteDir()
}
// CHANGE_ID is set only for pull requests, so it is safe to access the pullRequest global variable
if (env.CHANGE_ID) {
pullRequest.comment("Image pushed for Jenkins build [#${env.BUILD_NUMBER}](${env.BUILD_URL}):\n```\n${REPO}:${TAG}\n```")
}
}
}
}
stage('Tests') {
steps {
timeout(time: 135, unit: 'MINUTES') {
sh "$MAVEN_HOME/bin/mvn verify -B -e -DrerunFailingTestsCount=2 -Dmaven.test.failure.ignore=true -Dansi.strip=true -Pnative $ALT_TEST_BUILD"
}
// Remove any default TestNG report files as this will result in tests being counted twice by Jenkins statistics
sh "rm -rf **/target/*-reports*/**/TEST-TestSuite.xml"
// TODO Add StabilityTestDataPublisher after https://issues.jenkins-ci.org/browse/JENKINS-42610 is fixed
// Capture target/surefire-reports/*.xml, target/failsafe-reports/*.xml,
// target/failsafe-reports-embedded/*.xml, target/failsafe-reports-remote/*.xml
script {
def testResults = sh(
script: 'shopt -s nullglob globstar; ls **/target/*-reports*/**/TEST-*.xml | grep -v "FLAKY.xml" | paste -s -d, -',
returnStdout: true
).trim()
junit testResults: "${testResults}",
testDataPublishers: [[$class: 'ClaimTestDataPublisher']],
healthScaleFactor: 100, allowEmptyResults: true
}
// Workaround for SUREFIRE-1426: Fail the build if there a fork crashed
script {
if (manager.logContains("org.apache.maven.surefire.booter.SurefireBooterForkException:.*")) {
echo "Fork error found"
manager.buildFailure()
}
}
// Dump any dump files to the console
sh 'find . -name "*.dump*" -exec echo {} \\; -exec cat {} \\;'
sh 'find . -name "hs_err_*" -exec echo {} \\; -exec grep "^# " {} \\;'
}
}
stage('Deploy snapshot') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
// from Jenkins docs: Note that the build result can only get worse, so you cannot change the result to SUCCESS if the current result is UNSTABLE or worse
script {
if (!env.BRANCH_NAME.startsWith('PR-')) {
sh "$MAVEN_HOME/bin/mvn deploy -B -e -Pdistribution -Drelease-mode=upstream -DdeployServerZip=true -DskipTests -Dcheckstyle.skip=true"
}
}
}
}
}
}
post {
always {
// Record any warnings before the tests log their own stuff
recordIssues enabledForFailure: true,
forensicsDisabled: true,
blameDisabled: true,
quiet: true,
tools: [
mavenConsole(), java(), javaDoc(),
checkStyle(),
spotBugs(),
pmdParser(pattern: '**/target/pmd.xml'),
cpd(pattern: '**/target/cpd.xml')
]
script {
def TARGET_BRANCH = env.BRANCH_NAME.startsWith('PR-') ? env.CHANGE_TARGET : env.BRANCH_NAME
sh 'RUNNER_DEBUG=1 FLAKY_TEST_GLOB="**/target/*-reports*/**/TEST-*FLAKY.xml" PROJECT_KEY=ISPN TYPE=Bug JENKINS_JOB_URL=$BUILD_URL TARGET_BRANCH=${TARGET_BRANCH}./bin/jira/track_flaky_tests.sh'
}
}
// Send notification email when a build fails, has test failures, or is the first successful build
failure {
script {
echo "Build result notify policy is: ${params.BUILD_RESULT_NOTIFY}"
if (params.BUILD_RESULT_NOTIFY == 'EMAIL') {
echo 'Sending notify'
emailext to: '${DEFAULT_RECIPIENTS}', subject: '${DEFAULT_SUBJECT}',
body: '${DEFAULT_CONTENT}'
}
}
}
unstable {
script {
echo "Build result notify policy is: ${params.BUILD_RESULT_NOTIFY}"
if (params.BUILD_RESULT_NOTIFY == 'EMAIL') {
echo 'Sending notify'
emailext to: '${DEFAULT_RECIPIENTS}', subject: '${DEFAULT_SUBJECT}',
body: '${DEFAULT_CONTENT}'
}
}
}
fixed {
script {
echo "Build result notify policy is: ${params.BUILD_RESULT_NOTIFY}"
if (params.BUILD_RESULT_NOTIFY == 'EMAIL') {
echo 'Sending notify'
emailext to: '${DEFAULT_RECIPIENTS}', subject: '${DEFAULT_SUBJECT}',
body: '${DEFAULT_CONTENT}'
}
}
}
cleanup {
// Archive logs and dump files
sh 'find . \\( -name "*.log" -o -name "*.dump*" -o -name "hs_err_*" -o -name "*.hprof" \\) -exec xz -3 {} \\;'
archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.xz,**/*.log.gz,documentation/target/generated-html/**,**/target/*-reports*/**/TEST-*.xml'
// Remove all untracked files, ignoring .gitignore
sh 'git clean -qfdx || echo "git clean failed, exit code $?"'
// Remove all created SNAPSHOT artifacts to ensure a clean build on every run
sh 'find ~/.m2/repository -type d -name "*-SNAPSHOT" -prune -exec rm -rf {} \\;'
}
}
}