-
Notifications
You must be signed in to change notification settings - Fork 6
/
Jenkinsfile
332 lines (313 loc) · 11.1 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
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
import jenkins.*
import jenkins.model.*
import hudson.*
import hudson.model.*
def ASMCOV_URI
def withDockerNetwork(Closure inner) {
try {
networkId = UUID.randomUUID().toString()
sh "docker network create ${networkId}"
inner.call(networkId)
} finally {
sh "docker network rm ${networkId}"
}
}
def stages() {
def stages = ["elos", "build release", "build debug", "utest", "smoke test", "lint sources", "Benchmarks", "documentation", "integration test"]
if (env.BRANCH_NAME =~ 'story.*' || env.BRANCH_NAME =~ 'bug.*' || env.BRANCH_NAME =~ 'task.*' || env.BRANCH_NAME == 'integration' || env.BRANCH_NAME == 'master' ) {
stages.push("baseos-lab")
}
return stages
}
node {
ASMCOV_URI = ''
script {
def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl.class,
Jenkins.instance,
null,
null
);
def jenkins_asmcov_uri = creds.findResult { it.id == 'jenkins_asmcov_uri' ? it : null }
if(jenkins_asmcov_uri) {
println(jenkins_asmcov_uri.id + ": " +jenkins_asmcov_uri.username + ": " + jenkins_asmcov_uri.password)
ASMCOV_URI=jenkins_asmcov_uri.password
}
println("stages:" + stages())
}
}
node {
SOURCES_URI = ''
script {
def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl.class,
Jenkins.instance,
null,
null
);
def baseos_gitlab_uri = creds.findResult { it.id == 'baseos_gitlab_uri' ? it : null }
if(baseos_gitlab_uri) {
println(baseos_gitlab_uri.id + ": " +baseos_gitlab_uri.username + ": " + baseos_gitlab_uri.password)
SOURCES_URI=baseos_gitlab_uri.password
println("Sources URI is " + SOURCES_URI)
}
}
}
properties([gitLabConnection('GitLab')])
pipeline {
options {
gitlabBuilds(builds: stages() )
buildDiscarder(logRotator(numToKeepStr: env.BRANCH_NAME == "master"? "1000": env.BRANCH_NAME == "integration"?"1000":"3"))
}
environment {
SOURCES_URI = "${SOURCES_URI}"
ELOS_DEPENDENCY_CONFIG="./ci/dependencies_emlix.json"
}
agent none
stages {
stage("Elos Run") {
parallel {
stage('trigger baseos-lab') {
when { anyOf {
equals expected: true, actual: stages().findAll{"baseos-lab".toLowerCase().contains(it.toLowerCase())}.any{true}
}}
steps {
updateGitlabCommitStatus name: 'baseos-lab', state: 'skipped'
gitlabCommitStatus("baseos-lab") {
script {
echo "triggering eb-baseos-elos-baseos-lab Pipeline with elos Branch '${BRANCH_NAME}'"
build(job: 'eb-baseos-elos-baseos-lab',
wait: true,
parameters: [
string(name: 'ELOS_DEV_BRANCH', value: "${BRANCH_NAME}"),
]
)
}
}
}
}
stage("Build and test") {
agent {
dockerfile {
filename './ci/Dockerfile'
reuseNode true
additionalBuildArgs "--build-arg USER=jenkins \
--build-arg UID=\$(id -u) --build-arg GID=\$(id -g) --build-arg ASMCOV_URI=${ASMCOV_URI}"
args "--privileged --userns=keep-id -e SOURCES_URI=${SOURCES_URI} -e ELOS_DEPENDENCY_CONFIG=${ELOS_DEPENDENCY_CONFIG}"
label "podman"
}
}
stages {
stage('debug') {
steps{
sh 'ls -lah'
sh 'env'
sh 'gcc --version'
sh 'cmake --version'
updateGitlabCommitStatus name: 'elos', state: 'running'
}
}
stage('Build release') {
steps{
gitlabCommitStatus("build release") {
sh '''#!/bin/bash -xe
rm -rf ./build/deps
./ci/build.sh --ci Release
'''
}
}
}
stage('Build debug') {
steps{
gitlabCommitStatus("build debug") {
sh '''#!/bin/bash -xe
./ci/build.sh --ci Debug
'''
}
}
}
stage('Run UnitTest') {
steps {
gitlabCommitStatus("utest") {
sh '''#!/bin/bash -xe
./ci/run_utest.sh
./ci/run_utest.sh Release
'''
}
}
post {
always {
archiveArtifacts artifacts: "build/Debug/cmake/result/unit_test/,build/Release/result/unit_test/", fingerprint: true
script {
step (
[$class: 'JUnitResultArchiver', testResults: 'build/*/result/unit_test/junit.xml']
)
}
}
}
}
stage('Run Smoke Test') {
steps {
gitlabCommitStatus("smoke test") {
sh '''#!/bin/bash -xe
export SMOKETEST_TMP_DIR="$(realpath ./build/tmp)"
./ci/run_smoketests.sh Debug
./ci/run_smoketests.sh Release
'''
}
}
post {
always {
archiveArtifacts artifacts: "build/Debug/result/smoketest_results/,build/Release/result/smoketest_results/", fingerprint: true
}
}
}
stage('Lint sources') {
steps{
gitlabCommitStatus("lint sources") {
sh '''#!/bin/bash -xe
. ./ci/ignored_sources.sh
./ci/code_lint.py --ci
./ci/checklicense.sh
./ci/run_integration_tests_linter.sh Release
'''
}
}
post {
failure {
archiveArtifacts artifacts: "build/Release/result/integration/robot_lint/*.log", fingerprint: true
}
always {
archiveArtifacts artifacts: "build/Release/cmake/lint_results/**", fingerprint: true
}
}
}
stage('Build documentation') {
steps{
gitlabCommitStatus("documentation") {
sh './ci/build_doc.sh'
}
}
post {
success {
archiveArtifacts artifacts: "build/Debug/doc/**", fingerprint: true
}
}
}
stage('Run Benchmarks') {
steps {
gitlabCommitStatus("Benchmarks") {
sh './ci/run_benchmarks.sh Release'
}
}
post {
success {
archiveArtifacts artifacts: "build/Release/result/benchmark_results/**/*.csv", fingerprint: true
archiveArtifacts artifacts: "build/Release/result/benchmark_results/**/*.png", fingerprint: true
}
failure {
archiveArtifacts artifacts: "build/Release/result/benchmark_results/**", fingerprint: true
}
}
}
stage('Create coverage report') {
steps {
gitlabCommitStatus("coverage") {
sh '''#!/bin/bash -xe
./ci/create_coverage.sh
'''
}
}
post {
always {
archiveArtifacts artifacts: "build/Release/result/coverage_results/**", fingerprint: true
}
}
}
}
post {
success {
updateGitlabCommitStatus name: 'elos', state: 'success'
}
failure {
updateGitlabCommitStatus name: 'elos', state: 'failed'
}
always {
withCredentials([usernamePassword(credentialsId: 'kpi_creds', passwordVariable: 'KPI_API_TOKEN', usernameVariable: 'KPI_API_URL')]) {
sh './ci/publish_kpis.sh'
}
cleanWs(deleteDirs: true, patterns: [
[pattern: '*', type: 'INCLUDE'],
[pattern: 'samconf', type: 'EXCLUDE'],
[pattern: 'safu', type: 'EXCLUDE'],
[pattern: 'elos', type: 'EXCLUDE'],
[pattern: '*/build*', type: 'INCLUDE'],
])
}
}
}
stage ("Run integration test") {
agent {
label "docker"
}
environment {
DOCKER_BUILDKIT = 0
BUILD_ARG = "--build-arg USER=jenkins"
}
steps {
gitlabCommitStatus("integration test") {
sh '''#!/bin/bash -xe
./ci/run_integration_tests.sh Release
'''
}
}
post {
always {
archiveArtifacts artifacts: "build/Release/result/**", fingerprint: true
cleanWs(deleteDirs: true, patterns: [
[pattern: '*', type: 'INCLUDE'],
[pattern: 'samconf', type: 'EXCLUDE'],
[pattern: 'safu', type: 'EXCLUDE'],
[pattern: 'elos', type: 'EXCLUDE'],
[pattern: '*/build*', type: 'INCLUDE'],
])
}
}
}
}
}
}
post {
changed {
script {
def jobName = env.JOB_NAME.tokenize('/') as String[];
def projectName = jobName[0];
def title = '[' + projectName + '] '
def message = '';
if (currentBuild.currentResult == 'FAILURE') {
title += 'Pipeline for ' + env.BRANCH_NAME + ' has failed';
message = 'Hi, sorry but the pipeline is broken. See ' + env.BUILD_URL + ' for details.'
}
if(currentBuild.currentResult == 'SUCCESS') {
title += 'Pipeline for ' + env.BRANCH_NAME + ' is now stable again';
message = 'Hi, the pipeline is now stable again. See ' + env.BUILD_URL + ' for details.'
}
emailext subject: title,
body: message,
recipientProviders: [
[$class: 'CulpritsRecipientProvider'],
[$class: 'DevelopersRecipientProvider'],
[$class: 'RequesterRecipientProvider']
],
replyTo: '$DEFAULT_REPLYTO',
to: '$DEFAULT_RECIPIENTS'
}
}
success {
updateGitlabCommitStatus name: 'elos', state: 'success'
}
failure {
updateGitlabCommitStatus name: 'elos', state: 'failed'
}
}
}