-
Notifications
You must be signed in to change notification settings - Fork 229
/
Jenkinsfile
90 lines (77 loc) · 3 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
node {
properties([
pipelineTriggers(createPipelineTriggers()),
disableConcurrentBuilds(),
buildDiscarder(logRotator(numToKeepStr: '10'))
])
catchError {
stage('Checkout') {
checkout scm
}
stage('Build') {
mvn 'clean install -DskipTests'
archiveArtifacts '**/target/*.*ar'
}
parallel(
unitTest: {
stage('Unit Test') {
mvn 'test'
}
},
integrationTest: {
stage('Integration Test') {
if (isTimeTriggeredBuild()) {
mvn 'verify -DskipUnitTests -Parq-wildfly-swarm '
}
}
}
)
}
// Archive Unit and integration test results, if any
junit allowEmptyResults: true,
testResults: '**/target/surefire-reports/TEST-*.xml, **/target/failsafe-reports/*.xml'
mailIfStatusChanged env.EMAIL_RECIPIENTS
}
def createPipelineTriggers() {
if (env.BRANCH_NAME == 'master') {
// Run a nightly only for master
return [cron('H H(0-3) * * 1-5')]
}
return []
}
/**
* @return {@code true} if the build was time triggered, otherwise {@code false}
* @since workflow-support plugin 2.22
*/
boolean isTimeTriggeredBuild() {
for (Object currentBuildCause : currentBuild.getBuildCauses()) {
if (currentBuildCause._class.contains('TimerTriggerCause')) {
return true
}
}
return false
}
def mailIfStatusChanged(String recipients) {
// Also send "back to normal" emails. Mailer seems to check build result, but SUCCESS is not set at this point.
if (currentBuild.currentResult == 'SUCCESS') {
currentBuild.result = 'SUCCESS'
}
step([$class: 'Mailer', recipients: recipients])
}
def mvn(def args) {
def mvnHome = tool 'M3'
def javaHome = tool 'JDK8'
// Apache Maven related side notes:
// --batch-mode : recommended in CI to inform maven to not run in interactive mode (less logs)
// -V : strongly recommended in CI, will display the JDK and Maven versions in use.
// Very useful to be quickly sure the selected versions were the ones you think.
// -U : force maven to update snapshots each time (default : once an hour, makes no sense in CI).
// -Dsurefire.useFile=false : useful in CI. Displays test errors in the logs directly (instead of
// having to crawl the workspace files to see the cause).
// Advice: don't define M2_HOME in general. Maven will autodetect its root fine.
// See also
// https://github.com/jenkinsci/pipeline-examples/blob/master/pipeline-examples/maven-and-jdk-specific-version/mavenAndJdkSpecificVersion.groovy
withEnv(["JAVA_HOME=${javaHome}", "PATH+MAVEN=${mvnHome}/bin:${env.JAVA_HOME}/bin"]) {
sh "${mvnHome}/bin/mvn ${args} --batch-mode -V -U -e -Dsurefire.useFile=false"
}
}