forked from Pelagicore/softwarecontainer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
180 lines (154 loc) · 6.5 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
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
#!/usr/bin/groovy
/*
* Copyright (C) 2016-2017 Pelagicore AB
*
* Permission to use, copy, modify, and/or distribute this software for
* any purpose with or without fee is hereby granted, provided that the
* above copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
* BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*
* For further information see LICENSE
*/
// Runs a shell command in the vagrant vm
def runInVagrant = { String command ->
sh "cd ${env.WORKSPACE} && vagrant ssh -c 'cd softwarecontainer && ${command}'"
}
def shutdownVagrant = {
// In case the destroy step fails (happens sometimes with hung up ssh connections)
// we retry a couple of times to make sure it shuts down and is destroyed.
retry(5) {
sh "cd ${env.WORKSPACE} && vagrant destroy -f"
}
}
node {
try {
// Stages are subtasks that will be shown as subsections of the finiished build in Jenkins.
stage('Download') {
// Delete old files
sh 'rm -rf .[^.] .??* *'
// Checkout the git repository and refspec pointed to by jenkins
checkout scm
// Update the submodules in the repository.
sh 'git submodule update --init'
}
stage('StartVM') {
// Calculate available amount of RAM (excluding Swap)
String gigsramStr = sh (
script: 'free -g | grep "Mem: " | tail -n1 | awk \'{ print $2 }\'',
returnStdout: true
)
int gigsram = gigsramStr.trim() as Integer
// Only use half of the available memory if it is more than 2GB
if (gigsram >= 2) {
gigsram = gigsram / 2
println "Will set VAGRANT_RAM to ${gigsram}"
}
// Start the machine (destroy it if present) and provision it
shutdownVagrant()
withEnv(["VAGRANT_RAM=${gigsram}",
"APT_CACHE_SERVER=10.8.36.16"]) {
sh "cd ${env.WORKSPACE} && vagrant up"
}
}
// Configure the software with cmake
stage('Configure') {
String buildParams = "-DENABLE_COVERAGE=ON "
buildParams += "-DENABLE_USER_DOC=ON -DENABLE_API_DOC=ON "
buildParams += "-DENABLE_SYSTEMD=ON -DENABLE_PROFILING=ON "
buildParams += "-DENABLE_TEST=ON -DENABLE_EXAMPLES=ON"
// Remove old build directory
runInVagrant("rm -rf build")
// Run cmake
runInVagrant("cmake -H. -Bbuild ${buildParams}")
}
// We build the docs first because they are part of ALL
stage('API documentation') {
runInVagrant("cd build && make api-doc")
}
// We build the docs first because they are part of ALL
stage('User documentation') {
runInVagrant("cd build && make user-doc")
}
// Build the rest of the projekt
stage('Build') {
runInVagrant("cd build && make")
}
stage('Install') {
runInVagrant("cd build && sudo make install")
}
stage('UnitTest') {
// TODO: We should not run these tests as root, but while waiting for a fix in the
// agent implementation, we currently have to.
runInVagrant("sudo ./build/run-unit-tests.py")
}
stage('ComponentTest') {
// We run it in this way to avoid getting (unreachable) paths
runInVagrant("sudo ./build/run-component-tests.py")
}
stage('ServiceTest') {
runInVagrant("cd servicetest && sudo ./run-tests.sh")
}
stage('Clang') {
// Most build parameters default to off, but not tests. We don't want static
// analysis for our tests.
String buildParams = "-DENABLE_TEST=OFF"
runInVagrant("sh ./cookbook/build/clang-code-analysis.sh . clang ${buildParams}")
}
stage('Coverage') {
// We run it in this way to avoid getting (unreachable) paths
runInVagrant("sudo make -C build lcov")
}
stage('Examples') {
runInVagrant("cd examples && sudo ./run-tests.sh")
runInVagrant("cd doc && sudo ./run_examples.sh")
}
stage('Artifacts') {
// Store the artifacts of the entire build
archive "**/*"
// Save the coverage report for unit tests
publishHTML (target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'build/CoverageUnitTest',
reportFiles: 'index.html',
reportName: 'Coverage report'
])
publishHTML (target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'clang/scan_build_output/report',
reportFiles: 'index.html',
reportName: 'Clang report'
])
// Store the unit test results and graph them
step([$class: 'JUnitResultArchiver', testResults: '**/*_unittest_result.xml'])
// Store the component test results and graph them
step([$class: 'JUnitResultArchiver', testResults: '**/*_componenttest_result.xml'])
// Store the service test results and graph them
step([$class: 'JUnitResultArchiver', testResults: '**/*_servicetest_result.xml'])
}
}
catch(err) {
// Do not add a stage here.
// When "stage" commands are run in a different order than the previous run
// the history is hidden since the rendering plugin assumes that the system has changed and
// that the old runs are irrelevant. As such adding a stage at this point will trigger a
// "change of the system" each time a run fails.
println "Something went wrong!"
currentBuild.result = "FAILURE"
}
finally {
// Always try to shut down the machine
shutdownVagrant()
}
}