-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
330 lines (316 loc) · 13.2 KB
/
Copy pathJenkinsfile
File metadata and controls
330 lines (316 loc) · 13.2 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
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
#!/usr/bin/env groovy
@Library(value='jenkins-pipeline-scripts@master', changelog=false) _
String DOCKER_REGISTRY_HUB = env.DOCKER_REGISTRY_HUB ?: 'index.docker.io'.toLowerCase().trim() // registry.hub.docker.com
String DOCKER_ORGANISATION_HUB = 'nabla'.trim()
String DOCKER_IMAGE_TAG = env.DOCKER_IMAGE_TAG ?: 'latest'.trim()
//String DOCKER_USERNAME="nabla"
String DOCKER_NAME = 'ansible-jenkins-slave-docker'.trim()
String DOCKER_REGISTRY_HUB_URL = env.DOCKER_REGISTRY_HUB_URL ?: "https://${DOCKER_REGISTRY_HUB}".trim()
String DOCKER_REGISTRY_HUB_CREDENTIAL = env.DOCKER_REGISTRY_HUB_CREDENTIAL ?: 'hub-docker-nabla'.trim()
String DOCKER_IMAGE = "${DOCKER_ORGANISATION_HUB}/${DOCKER_NAME}:${DOCKER_IMAGE_TAG}".trim()
String DOCKER_OPTS_COMPOSE = getDockerOpts(isDockerCompose: true, isLocalJenkinsUser: false)
pipeline {
//agent none
//agent {
// label 'ubuntu'
//}
agent {
docker {
image DOCKER_IMAGE
alwaysPull true
reuseNode true
registryUrl DOCKER_REGISTRY_HUB_URL
registryCredentialsId DOCKER_REGISTRY_HUB_CREDENTIAL
args DOCKER_OPTS_COMPOSE
label 'ubuntu'
}
}
//agent {
// // Equivalent to "docker build -f Dockerfile-jenkins-slave-ubuntu:16.04 --build-arg FILEBEAT_VERSION=6.3.0 ./build/
// dockerfile {
// //filename 'Dockerfile'
// //dir 'build'
// label 'molecule'
// additionalBuildArgs ' --build-arg JENKINS_USER_HOME=/home/jenkins --label "version=1.0.1" --label "maintaner=Alban Andrieu <alban.andrieu@gmail.com>" '
// }
//}
parameters {
string(defaultValue: '', description: 'Default workspace suffix to override', name: 'WORKSPACE_SUFFIX', trim: true)
string(defaultValue: 'jenkins', description: 'User', name: 'TARGET_USER', trim: true)
booleanParam(defaultValue: false, description: 'Dry run', name: 'DRY_RUN')
booleanParam(defaultValue: false, description: 'Clean before run', name: 'CLEAN_RUN')
booleanParam(defaultValue: false, description: 'Debug run', name: 'DEBUG_RUN')
booleanParam(defaultValue: false, name: 'RELEASE', description: 'Perform release-type build.')
string(defaultValue: '', name: 'RELEASE_BASE', description: 'Commit tag or branch that should be checked-out for release', trim: true)
string(defaultValue: '', name: 'RELEASE_VERSION', description: 'Release version for artifacts', trim: true)
booleanParam(defaultValue: false, description: 'Build only to have package. no test / no docker', name: 'BUILD_ONLY')
booleanParam(defaultValue: true, description: 'Run acceptance tests', name: 'BUILD_TEST')
}
environment {
GIT_BRANCH_NAME = "${params.GIT_BRANCH_NAME}".trim()
//BRANCH_JIRA = "${env.BRANCH_NAME}".replaceAll("feature/","")
//PROJECT_BRANCH = "${env.GIT_BRANCH}".replaceFirst("origin/","")
CARGO_RMI_PORT = "${params.CARGO_RMI_PORT}"
//WORKSPACE_SUFFIX = "${params.WORKSPACE_SUFFIX}"
//echo "JOB_NAME: ${env.JOB_NAME} : ${env.JOB_BASE_NAME}"
//TARGET_PROJECT = sh(returnStdout: true, script: "echo ${env.JOB_NAME} | cut -d'/' -f -1").trim()
//BRANCH_NAME = "${env.BRANCH_NAME}".replaceAll("feature/","")
BUILD_ID = "${env.BUILD_ID}"
SERVER_URL = "${params.SERVER_URL}"
SERVER_CONTEXT = "${params.SERVER_CONTEXT}"
GIT_PROJECT = 'nabla'
GIT_BROWSE_URL = "https://github.com/AlbanAndrieu/${GIT_PROJECT}/"
GIT_URL = "ssh://git@github.com/AlbanAndrieu/${GIT_PROJECT}.git"
DOCKER_TAG = dockerTag()
ARCH = 'linux'
USE_SUDO = 'false'
}
options {
//skipDefaultCheckout()
disableConcurrentBuilds()
skipStagesAfterUnstable()
parallelsAlwaysFailFast()
ansiColor('xterm')
timeout(time: 120, unit: 'MINUTES', activity: true)
timestamps()
}
stages {
stage('Build-Docker') {
when {
expression { BRANCH_NAME ==~ /release\/.+|master|develop|PR-.*|feature\/.*|bugfix\/.*/ }
expression { params.BUILD_ONLY.toBoolean() == false }
}
steps {
script {
tee('python.log') {
sh '#!/bin/bash \n' +
"cd $WORKSPACE \n" +
'ls -lrta /opt/ansible/ \n' +
'. /opt/ansible/env38/bin/activate \n' +
'python -V \n' +
'python3 -V \n' +
'python3.8 -V \n' +
'pip -V \n' +
'pip list \n' +
'pip3.8 install conan pre-commit \n' +
'which conan \n' +
"conan remove --system-reqs '*' \n" +
'whoami \n' +
'bash ./scripts/cppcheck.sh\n' +
'source ./scripts/run-python.sh\n' +
'. ./scripts/run-python.sh\n' +
'pre-commit run -a || true'
} // tee
tee('build-docker.log') {
//sh "#!/bin/bash \n" +
// "conan remove --system-reqs '*'"
docker.withRegistry(DOCKER_REGISTRY_HUB_URL, DOCKER_REGISTRY_HUB_CREDENTIAL) {
def ansible = docker.build 'nabla/jenkins-slave-ubuntu:latest'
//ansible.inside {
// sh 'echo test'
//}
//ansible.push() // record this latest (optional)
//stage 'Test image'
stage('Test image') {
//docker run -i -t --entrypoint /bin/bash ${myImg.imageName()}
docker.image('nabla/jenkins-slave-ubuntu:latest').withRun { c ->
sh "docker logs ${c.id}"
}
}
// run some tests on it (see below), then if everything looks good:
//stage 'Approve image'
//ansible.push 'latest'
//def myImg = docker.image('nabla/jenkins-slave-ubuntu:latest')
//sh "docker push ${myImg.imageName()}"
//} // withCredentials
} // withRegistry
} // tee
} // script
} // steps
} // stage Build-Dcoker
stage('Build-Scons') {
steps {
script {
tee('build-scons.log') {
sh '#!/bin/bash \n' +
"cd $WORKSPACE \n" +
'ls -lrta /opt/ansible/ \n' +
'. /opt/ansible/env38/bin/activate \n' +
'python -V \n' +
'python3 -V \n' +
'python3.8 -V \n' +
'pip -V \n' +
'pip list \n' +
'pip3.8 install conan pre-commit cmake \n' +
'which conan \n' +
"conan remove --system-reqs '*' \n" +
'whoami \n' +
'bash ./scripts/cppcheck.sh\n' +
'bash ./scripts/flawfinder.sh\n' +
'bash ./scripts/clang-tidy.sh\n' +
'source ./scripts/run-python.sh\n' +
'rm -Rf /home/jenkins/.conan/\n' +
//"pre-commit run -a || true\n" +
'bash ./build.sh'
} // tee
publishHTML (target: [
allowMissing: true,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'reports/',
reportFiles: 'gcovr-report.html',
reportName: 'GCov Report'
])
} // script
} // steps
} // stage Build-CMake
stage('Build-CMake') {
when {
expression { BRANCH_NAME ==~ /release\/.+|master|develop|PR-.*|feature\/.*|bugfix\/.*/ }
//expression { params.BUILD_TEST.toBoolean() == true && params.BUILD_ONLY.toBoolean() == false }
}
steps {
script {
tee('build-cmake.log') {
//sh "#!/bin/bash \n" +
// "cd $WORKSPACE \n" +
// "ls -lrta /opt/ansible/ \n" +
// ". /opt/ansible/env38/bin/activate \n" +
// "python -V \n" +
// "python3 -V \n" +
// "python3.8 -V \n" +
// "pip -V \n" +
// "pip list \n" +
// "pip3.8 install conan pre-commit cmake \n" +
// "which conan \n" +
// "conan remove --system-reqs '*' \n" +
// "whoami \n" +
// "bash ./scripts/cppcheck.sh\n" +
// "source ./scripts/run-python.sh\n"
dir('sample/build-linux') {
sh '#!/bin/bash \n' +
//"source ../../scripts/run-python.sh\n" +
'. /opt/ansible/env38/bin/activate \n' +
'rm -Rf /home/jenkins/.conan/\n' +
'export USE_SUDO=false\n' +
"export UNIT_TESTS=${BUILD_TEST}\n" +
//"export ENABLE_MEMCHECK=true\n" +
'bash ./build.sh\n' +
'make cppcheck\n' +
'make clangtidy\n'
//"make sonarqube\n" +
//"make valgrind\n" +
//"make DoxygenDoc\n" +
//"make tests\n" +
//sh 'ctest -T test --no-compress-output'
} // dir
} // tee
publishHTML (target: [
allowMissing: true,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'sample/build-linux/coverage/',
reportFiles: 'index.html',
reportName: 'Coverage Report'
])
publishHTML (target: [
allowMissing: true,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'sample/build-linux/check/',
reportFiles: 'index.html',
reportName: 'Cppcheck Report'
])
publishHTML (target: [
allowMissing: true,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'sample/build-linux/doc/html/',
reportFiles: 'index.html',
reportName: 'Doxygen Report'
])
publishHTML (target: [
allowMissing: true,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'reports/',
reportFiles: 'flawfinder-result.html',
reportName: 'Flawfinder Report'
])
publishHTML (target: [
allowMissing: true,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'reports/',
reportFiles: 'rats-result.html',
reportName: 'Rats Report'
])
dockerHadoLint(dockerFilePath: '.', skipDockerLintFailure: true, dockerFileId: '1')
} // script
} // steps
} // stage Build-CMake
stage('SonarQube analysis') {
when {
expression { BRANCH_NAME ==~ /release\/.+|master|develop|PR-.*|feature\/.*|bugfix\/.*/ }
expression { params.BUILD_ONLY.toBoolean() == false }
}
environment {
SONAR_SCANNER_OPTS = '-Xmx1g'
}
steps {
sh '/usr/local/sonar-runner/bin/sonar-scanner -D sonar-project.properties'
}
} // stage SonarQube
//stage('Approve image') {
// sshagent(['jenkins-ssh']) {
//// def myImg = docker.image('nabla/jenkins-slave-ubuntu:latest')
//// sh "docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock nate/dockviz ${myImg.imageName()}"
// sh returnStdout: true, script: 'sudo docker run -it --net host --pid host --cap-add audit_control -v /var/lib:/var/lib -v /var/run/docker.sock:/var/run/docker.sock -v /usr/lib/systemd:/usr/lib/systemd -v /etc:/etc --label docker_bench_security docker/docker-bench-security'
//}
//}
} // stages
post {
always {
recordIssues enabledForFailure: true,
tools: [cppCheck(pattern: 'reports/cppcheck-result.xml'),
junitParser(pattern: 'sample/build-linux/Testing/JUnitTestResults.xml'),
//sonarQube(pattern: '**/sonar-report.json'),
// NOK sonarQube(pattern: '.scannerwork/report-task.txt'),
gcc(),
cmake(),
doxygen(),
//clang(),
//clangAnalyzer(),
clangTidy(), //**/clang-tidy-result.txt
//dockerLint(),
flawfinder(),
taskScanner()
]
archiveArtifacts artifacts: '**/conaninfo.txt, , *.log, sample/build*/CMakeFiles/CMakeOutput.log, sample/build*/CMakeFiles/CMakeError.log, bw-outputs/build-wrapper.log, bw-outputs/build-wrapper-dump.json', excludes: null, fingerprint: false, onlyIfSuccessful: false
// Archive the CTest xml output
archiveArtifacts (
artifacts: 'sample/build-linux/Testing/**/*.xml, sample/build-linux/Testing/Temporary/*',
fingerprint: true, onlyIfSuccessful: false
)
// Process the CTest xml output with the xUnit plugin
xunit (
testTimeMargin: '3000',
thresholdMode: 1,
thresholds: [
skipped(failureThreshold: '0'),
failed(failureThreshold: '0')
],
tools: [CTest(
pattern: 'sample/build-linux/Testing/**/Test.xml',
deleteOutputFiles: true,
failIfNotNew: false,
skipNoTestFiles: true,
stopProcessingIfError: true
)]
)
} // always
success {
archiveArtifacts '**/*.tar.gz, *.log, conaninfo.txt, sample/build-linux/DartConfiguration.tcl, sample/build-linux/install_manifest.txt, sample/build-linux/CMakeCache.txt, sample/build-linux/graphviz.png, sample/build-linux/iwyu.out, sample/build-linux/bin/*, sample/build-linux/lib/*, sample/build-linux/_CPack_Packages/Linux/DEB/*'
} // success
} // post
} // pipeline