forked from infinispan/infinispan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
235 lines (205 loc) · 10.5 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
#!/usr/bin/env groovy
pipeline {
agent {
label 'slave-group-normal'
}
parameters {
choice(name: 'TEST_JDK', choices: ['Default', 'JDK 11', 'JDK 17', 'JDK 20'], description: 'The JDK used to run tests')
}
options {
timeout(time: 4, unit: 'HOURS')
timestamps()
buildDiscarder(logRotator(numToKeepStr: '100', daysToKeepStr: '61'))
}
stages {
stage('Prepare') {
steps {
script {
// Show the agent name in the build list
echo env.NODE_NAME
env.MAVEN_HOME = tool('Maven')
env.MAVEN_OPTS = "-Xmx1g -XX:+HeapDumpOnOutOfMemoryError"
env.JAVA_HOME = tool('JDK 17')
env.GRAALVM_HOME = tool('GraalVM 20')
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 dependency-check:check"
}
sh 'cleanup.sh'
}
}
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
configFileProvider([configFile(fileId: 'maven-settings-with-deploy-snapshot', variable: 'MAVEN_SETTINGS')]) {
sh "$MAVEN_HOME/bin/mvn clean install $REPORTS_BUILD -B -V -e -s $MAVEN_SETTINGS -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 {
configFileProvider([configFile(fileId: 'maven-settings-with-deploy-snapshot', variable: 'MAVEN_SETTINGS')]) {
sh "$MAVEN_HOME/bin/mvn verify -B -V -e -s $MAVEN_SETTINGS -Dmaven.test.failure.ignore=true -Dansi.strip=true -Pnative $ALT_TEST_BUILD"
}
// 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
junit testResults: '**/target/*-reports*/**/TEST-*.xml',
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 "^# " {} \\;'
}
}
}
post {
always {
// Record any warnings before the tests log their own stuff
recordIssues enabledForFailure: true,
forensicsDisabled: true,
blameDisabled: true,
tools: [
mavenConsole(), java(), javaDoc(),
checkStyle(),
spotBugs(),
pmdParser(pattern: '**/target/pmd.xml'),
cpd(pattern: '**/target/cpd.xml')
]
}
// Deploy snapshots of successful master builds
success {
script {
if (!env.BRANCH_NAME.startsWith('PR-')) {
configFileProvider([configFile(fileId: 'maven-settings-with-deploy-snapshot', variable: 'MAVEN_SETTINGS')]) {
sh "$MAVEN_HOME/bin/mvn deploy -B -V -e -s $MAVEN_SETTINGS -Pdistribution -DdeployServerZip=true -Dmaven.main.skip=true -Dmaven.test.skip=true"
}
}
}
}
// 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 {} \\;'
}
}
}