forked from jenkinsci/git-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
106 lines (89 loc) · 3.71 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
#!groovy
/* Only keep the 10 most recent builds. */
properties([[$class: 'BuildDiscarderProperty',
strategy: [$class: 'LogRotator', numToKeepStr: '10']]])
node {
stage('Checkout') {
checkout scm
}
stage('Build') {
/* Call the maven build (with timeout). No tests. */
timeout(5) {
mvn "clean install -B -V -U -e -DskipTests"
}
}
stage('Test') {
/* Run tests in parallel on multiple nodes (with timeout). */
timeout(20) {
runParallelTests()
}
}
/* Save Results. */
stage('Results') {
/* Archive the build artifacts */
archive includes: 'target/*.hpi,target/*.jpi'
}
}
void runParallelTests() {
/* Request the test groupings. Based on previous test exection. */
/* see https://wiki.jenkins-ci.org/display/JENKINS/Parallel+Test+Executor+Plugin and demo on github
/* Using arbitrary parallelism of 4 and "generateInclusions" feature added in v1.8. */
def splits = splitTests parallelism: [$class: 'CountDrivenParallelism', size: 3], generateInclusions: true
/* Create dictionary to hold set of parallel test executions. */
def testGroups = [:]
for (int i = 0; i < splits.size(); i++) {
def split = splits[i]
/* Loop over each record in splits to prepare the testGroups that we'll run in parallel. */
/* Split records returned from splitTests contain { includes: boolean, list: List<String> }. */
/* includes = whether list specifies tests to include (true) or tests to exclude (false). */
/* list = list of tests for inclusion or exclusion. */
/* The list of inclusions is constructed based on results gathered from */
/* the previous successfully completed job. One addtional record will exclude */
/* all known tests to run any tests not seen during the previous run. */
testGroups["split${i}"] = { // example, "split3"
node ('highmem'){
checkout scm
/* Clean each test node to start. */
mvn 'clean -B -V -U -e'
def mavenInstall = 'install -B -V -U -e -Dsurefire.useFile=false -Dmaven.test.failure.ignore=true'
/* Write includesFile or excludesFile for tests. Split record provided by splitTests. */
/* Tell maven to read the appropriate file. */
if (split.includes) {
writeFile file: "target/parallel-test-inclusions.txt", text: split.list.join("\n")
mavenInstall += " -Dsurefire.includesFile=target/parallel-test-inclusions.txt"
} else {
writeFile file: "target/parallel-test-exclusions.txt", text: split.list.join("\n")
mavenInstall += " -Dsurefire.excludesFile=target/parallel-test-exclusions.txt"
}
/* Call the maven build with tests. */
mvn mavenInstall
/* Archive the test results */
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
}
}
}
parallel testGroups
}
/* Run maven from tool "mvn" */
void mvn(def args) {
/* Get jdk tool. */
String jdktool = tool name: "jdk7", type: 'hudson.model.JDK'
/* Get the maven tool. */
def mvnHome = tool name: 'mvn'
/* Set JAVA_HOME, and special PATH variables. */
List javaEnv = [
"PATH+JDK=${jdktool}/bin", "JAVA_HOME=${jdktool}",
'_JAVA_OPTIONS=-XX:MaxPermSize=160m -Xmx256m -Djava.awt.headless=true',
// Additional variables needed by tests on machines
// that don't have global git user.name and user.email configured.
'[email protected]','GIT_COMMITTER_NAME=Hates','GIT_AUTHOR_NAME=Cake','[email protected]', 'LOGNAME=hatescake'
]
/* Call maven tool with java envVars. */
withEnv(javaEnv) {
if (isUnix()) {
sh "${mvnHome}/bin/mvn ${args}"
} else {
bat "${mvnHome}\\bin\\mvn ${args}"
}
}
}