-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
153 lines (145 loc) · 3.7 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
def previousSuccessBuildHash = 'null'
def commitsCount = 0
def next = 'null'
def tests_pass = true
pipeline {
agent any
options { disableConcurrentBuilds() }
stages {
stage('Copy Archive') {
steps {
script {
if (currentBuild.previousBuild) {
try {
copyArtifacts(projectName: currentBuild.projectName)
} catch(err) {
// ignore error
}
}
}
}
}
stage('Setup Jenkins'){
steps{
script{
if (!fileExists('commitsCount.txt')) {
writeFile file: './commitsCount.txt', text: "$commitsCount"
}
if (!fileExists('previousSuccessBuildHash.txt')) {
writeFile file: './previousSuccessBuildHash.txt', text: "$previousSuccessBuildHash"
}
}
}
}
stage('Previously Success Build Hash Stored?') {
steps {
script {
previousSuccessBuildHash = readFile('previousSuccessBuildHash.txt').trim()
}
}
}
stage('8 or more commits?'){
steps {
script {
tmp = readFile('commitsCount.txt').trim()
echo "$tmp"
commitsCount= tmp as int
}
}
}
stage('Increase Count') {
when {
expression { commitsCount < 8 }
}
steps {
script {
commitsCount++
next = 'finish'
}
writeFile file: './commitsCount.txt', text: "$commitsCount"
}
}
stage('Build') {
when {
expression { previousSuccessBuildHash == 'null' || commitsCount >= 8 }
}
steps {
sh 'mvn clean compile'
script {
next = 'test'
}
}
}
stage('Test') {
when {
expression { next == 'test' }
}
steps {
script {
try{
sh 'mvn test'
script {
next = 'package'
}
}
catch(e) {
next = 'finish'
tests_pass = false
}
}
}
}
stage('Git Bisect') {
when {
expression { tests_pass == false && previousSuccessBuildHash != 'null' }
}
steps {
script {
commitId = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
echo "$commitId"
echo "$previousSuccessBuildHash"
sh "git bisect start ${commitId} ${previousSuccessBuildHash}"
sh "git bisect run mvn clean test"
}
}
}
stage('Package') {
when {
expression { next == 'package' }
}
steps {
sh 'mvn package'
script {
next = 'finish'
commitId = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
writeFile file: './previousSuccessBuildHash.txt', text: "$commitId"
if(commitsCount>=8){
//reset counter since batch finished
commitsCount = 0
writeFile file: './commitsCount.txt', text: "$commitsCount"
}
}
}
}
stage('Finish') {
when {
expression { next == 'finish' }
}
steps {
script {
if(tests_pass){
currentBuild.result = "SUCCESS"
} else {
currentBuild.result = "FAILURE"
}
}
}
}
}
post {
always {
archiveArtifacts artifacts: 'previousSuccessBuildHash.txt', onlyIfSuccessful: true
archiveArtifacts artifacts: 'commitsCount.txt', onlyIfSuccessful: true
}
}
}