-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
106 lines (102 loc) · 3.38 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
// Documentation for Jenkinsfile https://jenkins.io/doc/book/pipeline/jenkinsfile/
pipeline {
agent any
triggers {
// timer trigger for "nightly build" on master branch
cron( env.BRANCH_NAME.equals('master') ? 'H H(0-3) * * 1-5' : '')
}
tools {
// Jenkins should install these tools into the VM (if not already there)
maven 'maven-3.6.0'
jdk 'jdk11'
}
stages {
stage ('Setup Environment') {
// always runs this stage
steps {
sh '''
echo "PATH = ${PATH}"
echo "M2_HOME = ${M2_HOME}"
mvn --version
'''
}
}
stage ('Build') {
// always runs this stage
steps {
sh 'mvn -B -DskipTests clean package'
}
}
stage ('Unit Tests') {
// run this stage when the commit message does not have [skip-ci
// for example, normal unit tests (unless the user is committing documentation only and there is no need)
when {
not {
changelog '\\[skip-ci\\]'
}
}
steps {
sh 'mvn test'
}
post {
always {
junit 'target/surefire-reports/*.xml'
}
}
}
stage ('Matrix Parallel Steps') {
// only run this stage when triggered by a cron timer and the commit does not have []skip-ci in the message
// for example, only run integration tests during the timer triggered nightly build
when {
allOf {
triggeredBy 'TimerTrigger'
not {
changelog '\\[skip-ci\\]'
}
}
}
matrix {
// run test groups in parallel. unit tests tagged as SetA, B, and C should run in parallel.
axes {
// matrix supports more than one axis, for multi-dimensional parallelism.
axis {
name 'TESTGROUP'
values 'SetA', 'SetB', 'SetC'
}
}
stages {
stage('Test') {
steps {
sh 'mvn test -Dtest.groups="${TESTGROUP}"'
}
}
}
}
// after all sets are complete, the job will continue here.
}
stage ('After Matrix') {
// only run this stage when triggered by a cron timer and the commit does not have []skip-ci in the message
when {
allOf {
triggeredBy 'TimerTrigger'
not {
changelog '\\[skip-ci\\]'
}
}
}
steps {
sh 'echo "All matrix should be done"'
junit 'target/surefire-reports/*.xml'
}
}
stage ('Deploy Release') {
// this stage should be skipped unless the build was triggered by a new tag
when {
tag "release-*"
}
steps {
sh 'echo Deploy artifact to a repo'
}
}
}
}