forked from couchbase/couchbase-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
224 lines (194 loc) · 9.27 KB
/
Jenkinsfile
File metadata and controls
224 lines (194 loc) · 9.27 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env groovy
/**
* When updating this Jenkinsfile, changes will not take effect immediately; they will
* take effect once the Jenkins multi-branch pipeline picks up the commit. This therefore
* means that changes made to the Jenkinsfile in a Gerrit review will not have any effect
* until they are submitted.
*/
import hudson.model.Result
import hudson.model.Run
import jenkins.model.CauseOfInterruption.UserInterruption
pipeline {
agent { label "ubuntu-18.04&&master" }
environment {
PROJECTPATH="${WORKSPACE}/couchbase-cli"
CMAKE_CURRENT_BINARY_DIR="${PROJECTPATH}/install"
CMAKE_CURRENT_SOURCE_DIR="${PROJECTPATH}"
PATH="${PATH}:${WORKSPACE}/snappy-build/usr/local/include:/home/couchbase/.local/bin"
LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${WORKSPACE}/snappy-build/usr/local/lib"
DYLD_LIBRARY_PATH="${DYLD_LIBRARY_PATH}:${WORKSPACE}/snappy-build/usr/local/include"
}
stages {
stage("Setup") {
steps {
script {
// Configure Gerrit Trigger
properties([pipelineTriggers([
gerrit(
serverName: "review.couchbase.org",
gerritProjects: [
[
compareType: "PLAIN", disableStrictForbiddenFileVerification: false, pattern: "couchbase-cli",
branches: [[ compareType: "PLAIN", pattern: "master" ]]
],
],
triggerOnEvents: [
commentAddedContains(commentAddedCommentContains: "reverify"),
draftPublished(),
patchsetCreated(excludeNoCodeChange: true)
]
)
])])
}
slackSend(
channel: "#tooling-cv",
color: "good",
message: "Build for '<${GERRIT_CHANGE_URL}|${GERRIT_CHANGE_SUBJECT}>' by '${GERRIT_CHANGE_OWNER_NAME}' started (${env.BUILD_URL})"
)
timeout(time: 10, unit: "MINUTES") {
sh "pip3 install --user urllib3 pylint requests mypy==0.730 coverage==5.2 pytest==5.4.3"
}
// preventively delete the cli path to avoid issues with cloning
dir("${PROJECTPATH}") {
deleteDir()
}
dir("${WORKSPACE}") {
sh "git clone git@github.com:couchbase/couchbase-cli.git"
}
// Fetch the commit we are testing
dir("${PROJECTPATH}") {
sh "git fetch ssh://buildbot@review.couchbase.org:29418/couchbase-cli ${GERRIT_REFSPEC}"
sh "git checkout FETCH_HEAD"
}
}
}
stage("Build Dependencies") {
steps {
timeout(time: 10, unit: "MINUTES") {
sh "mkdir snappy-build"
// paranoid cleanup
dir("${WORKSPACE}/snappy") {
deleteDir()
}
dir("${WORKSPACE}") {
sh "git clone -b 1.1.7 https://github.com/google/snappy.git"
}
dir("${WORKSPACE}/snappy/build") {
sh "cmake ../ -DBUILD_SHARED_LIBS=ON"
sh "DESTDIR=${WORKSPACE}/snappy-build make install"
sh "CXXFLAGS=\"-I${WORKSPACE}/snappy-build/usr/local/include -L${WORKSPACE}/snappy-build/usr/local/lib\" CFLAGS=\"-I${WORKSPACE}/snappy-build/usr/local/include -L${WORKSPACE}/snappy-build/usr/local/lib\" CPPFLAGS=\"-I${WORKSPACE}/snappy-build/usr/local/include -L${WORKSPACE}/snappy-build/usr/local/lib\" pip3 install --user python-snappy"
}
}
}
}
stage("Lint") {
steps {
timeout(time: 10, unit: "MINUTES") {
dir("${PROJECTPATH}") {
sh "python3 -m pylint -E --disable=import-error cbbackup cbbackupwrapper cblogredaction cbrecovery cbrestore cbrestorewrapper cbtransfer cbworkloadgen couchbase-cli pump*.py"
sh "python3 -m pylint --disable=import-error,unused-import --disable C,R cbmgr.py cluster_manager.py"
}
}
}
}
stage("Spell check docs") {
steps {
dir("${PROJECTPATH}") {
sh "./jenkins/adoc-lint.sh"
}
}
}
stage("Type check") {
steps {
timeout(time: 10, unit: "MINUTES") {
dir("${PROJECTPATH}") {
sh """#!/bin/bash
if [ \$(mypy --ignore-missing-imports cbbackup | grep -c error) -gt 1 ]; then
echo "Failed mypy type checking in cbbackup"
echo "Re running: mypy --ignore-missing-imports cbbackup"
echo \$(mypy --ignore-missing-imports cbbackup)
exit 1
fi
"""
sh """#!/bin/bash
if [ \$(mypy --ignore-missing-imports cbrestore | grep -c error) -gt 1 ]; then
echo "Failed mypy type checking in cbrestore"
echo "Re running: mypy --ignore-missing-imports cbrestore"
echo \$(mypy --ignore-missing-imports cbrestore)
exit 1
fi
"""
sh """#!/bin/bash
if [ \$(mypy --ignore-missing-imports cbtransfer | grep -c error) -gt 1 ]; then
echo "Failed mypy type checking in cbtransfer"
echo "Re running: mypy --ignore-missing-imports cbtransfer"
echo \$(mypy --ignore-missing-imports cbtransfer)
exit 1
fi
"""
sh """#!/bin/bash
if [ \$(mypy --ignore-missing-imports cbworkloadgen | grep -c error) -gt 1 ]; then
echo "Failed mypy type checking in cbworkloadgen"
echo "Re running: mypy --ignore-missing-imports cbworkloadgen"
echo \$(mypy --ignore-missing-imports cbworkloadgen)
exit 1
fi
"""
}
}
}
}
stage("Test") {
steps {
// Make reports directory if it does not exist
sh "mkdir -p ${WORKSPACE}/reports"
dir("${PROJECTPATH}"){
// Use pytest to run the test as it is nicer and also can produce junit xml reports
sh "coverage run --source . -m pytest test/test_*.py --cache-clear --junitxml=${WORKSPACE}/reports/test-cli.xml -v"
// Produce xml report for cobertura
sh "coverage xml -o ${WORKSPACE}/reports/coverage-cli.xml"
}
}
}
}
post {
always {
// Post the test results
junit allowEmptyResults: true, testResults: "reports/test-*.xml"
// Post the test coverage
cobertura autoUpdateStability: false, autoUpdateHealth: false, onlyStable: false, coberturaReportFile: "reports/coverage-*.xml", conditionalCoverageTargets: "70, 10, 30", failNoReports: false, failUnhealthy: true, failUnstable: true, lineCoverageTargets: "70, 10, 30", methodCoverageTargets: "70, 10, 30", maxNumberOfBuilds: 0, sourceEncoding: "ASCII", zoomCoverageChart: false
}
success {
slackSend(
channel: "#tooling-cv",
color: "good",
message: "Build for '<${GERRIT_CHANGE_URL}|${GERRIT_CHANGE_SUBJECT}>' by '${GERRIT_CHANGE_OWNER_NAME}' succeeded (${env.BUILD_URL})"
)
}
unstable {
slackSend(
channel: "#tooling-cv",
color: "bad",
message: "Build for '<${GERRIT_CHANGE_URL}|${GERRIT_CHANGE_SUBJECT}>' by '${GERRIT_CHANGE_OWNER_NAME}' is unstable (${env.BUILD_URL})"
)
}
failure {
slackSend(
channel: "#tooling-cv",
color: "bad",
message: "Build for '<${GERRIT_CHANGE_URL}|${GERRIT_CHANGE_SUBJECT}>' by '${GERRIT_CHANGE_OWNER_NAME}' failed (${env.BUILD_URL})"
)
}
aborted {
slackSend(
channel: "#tooling-cv",
color: "bad",
message: "Build for '<${GERRIT_CHANGE_URL}|${GERRIT_CHANGE_SUBJECT}>' by '${GERRIT_CHANGE_OWNER_NAME}' aborted (${env.BUILD_URL})"
)
}
cleanup {
// Remove the workspace
deleteDir()
}
}
}