/
Jenkinsfile
221 lines (194 loc) · 7.02 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
#!/usr/bin/env groovy
@Library('github.com/zanata/zanata-pipeline-library@master')
/* Only keep the 10 most recent builds. */
def projectProperties = [
[
$class: 'BuildDiscarderProperty',
strategy: [$class: 'LogRotator', numToKeepStr: '10']
],
]
properties(projectProperties)
def surefireTestReports='target/surefire-reports/TEST-*.xml'
/* Upto stash stage should fail fast:
* Failed and stop the build
* Yet able to create report
*/
timestamps {
node {
ansicolor {
try {
stage('Checkout') {
info.printNode()
notify.started()
// Shallow Clone does not work with RHEL7, which use git-1.8.3
// https://issues.jenkins-ci.org/browse/JENKINS-37229
checkout scm
// Clean the workspace
sh "git clean -fdx"
}
stage('Check build tools') {
info.printNode()
// TBD: whether install tools using Jenkinsfile
// Note: if next step happens on another node, mvnw might have to download again
sh "./mvnw --version"
}
stage('Pre-build'){
info.printNode()
/* Check Translation */
sh """./run-clean.sh ./mvnw -e \
com.googlecode.l10n-maven-plugin:l10n-maven-plugin:1.8:validate \
-pl :zanata-war -am -DexcludeFrontend \
"""
}
// Build and Unit Tests
// The result is archived for integration tests in other nodes.
stage('Build') {
info.printNode()
info.printEnv()
def jarFiles = 'target/*.jar'
def warFiles = 'target/*.war'
// globstar might failed to match
sh "find . -path \"*/${surefireTestReports}\" -delete"
sh "find . -path \"*/${jarFiles}\" -delete"
sh "find . -path \"*/${warFiles}\" -delete"
// Continue building even when test failure
// Thus -Dmaven.test.failure.ignore is required
sh """./run-clean.sh ./mvnw -e clean install jxr:aggregate\
--batch-mode \
--settings .travis-settings.xml \
--update-snapshots \
-DstaticAnalysis \
-Dchromefirefox \
-DskipFuncTests \
-DskipArqTests \
-Dmaven.test.failure.ignore \
"""
setJUnitPrefix("UNIT", surefireTestReports)
junit([
testResults: "**/${surefireTestReports}"
])
// notify if compile+unit test successful
notify.testResults("UNIT")
archive "**/${jarFiles},**/${warFiles}"
step([ $class: 'JacocoPublisher' ])
}
stage('stash') {
stash name: 'workspace', includes: '**/target/**,.mvn/**,server/zanata-frontend/src/**,server/'
}
} catch (e) {
notify.failed()
currentBuild.result = 'FAILURE'
throw e
}
}
}
if ( currentBuild.result == null ) {
stage('Integration tests') {
try {
def tasks = [:]
tasks["Integration tests: WILDFLY"] = {
integrationTests('wildfly8')
}
tasks["Integration tests: JBOSSEAP"] = {
integrationTests('jbosseap6')
}
tasks.failFast = true
parallel tasks
// notify.successful()
} catch (e) {
// When it cannot find the failfast report
echo "ERROR integrationTests: ${e.toString()}"
}
}
// TODO notify finish
// TODO in case of failure, notify culprits via IRC and/or email
// https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin#Email-extplugin-PipelineExamples
// http://stackoverflow.com/a/39535424/14379
// IRC: https://issues.jenkins-ci.org/browse/JENKINS-33922
// possible alternatives: Slack, HipChat, RocketChat, Telegram?
}
}
// TODO factor these out into zanata-pipeline-library too
void xvfb(Closure wrapped) {
wrap([$class: 'Xvfb', autoDisplayName: true, debug: true]) {
wrapped.call()
}
}
void debugChromeDriver() {
sh returnStatus: true, script: 'which chromedriver google-chrome'
sh returnStatus: true, script: 'ls -l /opt/chromedriver /opt/google/chrome/google-chrome'
}
void integrationTests(String appserver) {
def failsafeTestReports='target/failsafe-reports/TEST-*.xml'
node {
info.printNode()
info.printEnv()
echo "WORKSPACE=${env.WORKSPACE}"
checkout scm
// Clean the workspace
sh "git clean -fdx"
debugChromeDriver()
unstash 'workspace'
// TODO: Consider touching the target files for test, so it won't recompile
// Are jar files actually in?
def jarFileList = findFiles glob: "**/*.jar"
echo "${jarFileList.join('\n')}"
echo "${jarFileList.size()} jar files"
sh "touch ${jarFileList.join(' ')}"
try {
xvfb {
withPorts {
// Run the maven build
sh """./run-clean.sh ./mvnw -e -T 1 install \
--batch-mode \
--settings .travis-settings.xml \
-Danimal.sniffer.skip=true \
-DstaticAnalysis=false \
-Dcheckstyle.skip \
-Dappserver=$appserver \
-Dcargo.debug.jvm.args= \
-DskipUnitTests \
-Dmaven.main.skip \
-Dgwt.compiler.skip \
-Dwebdriver.display=${env.DISPLAY} \
-Dwebdriver.type=chrome \
-Dwebdriver.chrome.driver=/opt/chromedriver \
"""
// TODO -DallFuncTests
}
}
} catch(e) {
// Exception will be thrown if maven fails fast, i.e. a test fails
echo "ERROR integrationTests(${appserver}): ${e.toString()}"
currentBuild.result = 'UNSTABLE'
archive(
includes: '*/target/**/*.log,*/target/screenshots/**,**/target/site/xref/**',
excludes: '**/BACKUP-*.log')
} finally {
setJUnitPrefix(appserver, failsafeTestReports)
junit([
testResults: "**/${failsafeTestReports}"
// testDataPublishers: [[$class: 'StabilityTestDataPublisher']]
])
notify.testResults(appserver.toUpperCase())
}
}
}
void withPorts(Closure wrapped) {
def ports = sh(script: 'server/etc/scripts/allocate-jboss-ports', returnStdout: true)
withEnv(ports.trim().readLines()) {
wrapped.call()
}
}
// Modify classnames of tests, to avoid collision between EAP and WildFly test runs.
// We also use this to distinguish unit tests from integration tests.
// from https://issues.jenkins-ci.org/browse/JENKINS-27395?focusedCommentId=256459&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-256459
void setJUnitPrefix(prefix, files) {
// add prefix to qualified classname
def reportFiles = findFiles glob: "**/${files}"
if (reportFiles.size() > 0){
sh "sed -i \"s/\\(<testcase .*classname=['\\\"]\\)\\([a-z]\\)/\\1${prefix.toUpperCase()}.\\2/g\" ${reportFiles.join(" ")}"
}else{
echo "[WARNING] Failed to find JUnit report files **/${files}"
}
}