forked from infinispan/infinispan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
151 lines (131 loc) · 6.15 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
#!/usr/bin/env groovy
pipeline {
agent {
label 'slave-group-normal'
}
options {
timeout(time: 4, unit: 'HOURS')
timestamps()
buildDiscarder(logRotator(numToKeepStr: '100', daysToKeepStr: '61'))
}
stages {
stage('Prepare') {
steps {
// Show the agent name in the build list
script {
// The manager variable requires the Groovy Postbuild plugin
manager.addShortText(env.NODE_NAME, "grey", "", "0px", "")
}
// Workaround for JENKINS-47230
script {
env.MAVEN_HOME = tool('Maven')
env.MAVEN_OPTS = "-Xmx800m -XX:+HeapDumpOnOutOfMemoryError"
env.JAVA_HOME = tool('JDK 11')
}
// ISPN-9703 Ensure distribution build works on non-prs
script {
env.DISTRIBUTION_BUILD = env.BRANCH_NAME.startsWith('PR-') && !pullRequest.labels.contains('Documentation') ? "" : "-Pdistribution"
}
// Collect reports on non-prs
script {
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 $DISTRIBUTION_BUILD"
}
}
}
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"
}
// 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 {
recordIssues enabledForFailure: true, tools: [mavenConsole(), java(), javaDoc()]
recordIssues enabledForFailure: true, tool: checkStyle()
recordIssues enabledForFailure: true, tool: spotBugs()
recordIssues enabledForFailure: true, tool: pmdParser(pattern: '**/target/pmd.xml')
recordIssues enabledForFailure: true, tool: 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 {} \\;'
archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.xz,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 {} \\;'
}
}
}