-
Notifications
You must be signed in to change notification settings - Fork 1
/
lcov_1
336 lines (304 loc) · 13.7 KB
/
lcov_1
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
333
334
335
336
pipeline {
agent {
node {
label 'jenkinspool1'
}
}
//agent {
// docker {
// image 'cppalliance/boost_superproject_build:24.04-v1'
// // label 'jenkinspool1'
// }
//}
stages {
stage('Preclean Workspace') {
steps {
sh '''#!/bin/bash
set -xe
rm -rf * .*
# lcov is using ../boost-root. It could re-used but what if
# multiple jobs are sharing that directory over time. For now, clear it.
rm -rf ../boost-root || true
# The lcov tests are also using the following directory. Remove that.
TMPREPONAME=$(basename -s .git "$(git config --get remote.origin.url)")
TMPDIRNAME=${TMPREPONAME}-target-branch-iteration
rm -rf ../${TMPDIRNAME} || true
'''
checkout scm
}
}
stage('Set Variables') {
steps {
sh '''#!/bin/bash -xe
echo "" > jenkinsjobinfo.sh
chmod 777 jenkinsjobinfo.sh
REPONAME=$(basename -s .git "$(git config --get remote.origin.url)")
# REPONAME=$(basename `git rev-parse --show-toplevel`)
DNSREPONAME=$(echo $REPONAME | tr '_' '-')
ORGANIZATION=$(basename $(dirname "${GIT_URL}"))
if [[ "${GIT_URL}" =~ sdarwin ]]; then
# testing environment
echo "export JENKINS_CI_REPO=sdarwin/jenkins-ci" >> jenkinsjobinfo.sh
echo "export JENKINS_CI_REPO_BRANCH=testing" >> jenkinsjobinfo.sh
else
# standard
echo "export JENKINS_CI_REPO=cppalliance/jenkins-ci" >> jenkinsjobinfo.sh
echo "export JENKINS_CI_REPO_BRANCH=master" >> jenkinsjobinfo.sh
fi
echo "export PRTEST=prtest" >> jenkinsjobinfo.sh
echo "export REPONAME=${REPONAME}" >> jenkinsjobinfo.sh
echo "export DNSREPONAME=${DNSREPONAME}" >> jenkinsjobinfo.sh
echo "export ORGANIZATION=${ORGANIZATION}" >> jenkinsjobinfo.sh
echo "export ONLY_BUILD_ON_DOCS_MODIFICATION=false" >> jenkinsjobinfo.sh
echo "export PATH_TO_DOCS=libs/${REPONAME}/doc" >> jenkinsjobinfo.sh
'''
}
}
stage('Diagnostics') {
steps {
sh '''#!/bin/bash
set -x
# not set -e. errors may occur in diagnostics
cat jenkinsjobinfo.sh
. jenkinsjobinfo.sh
ls -al
cat /etc/os-release
pwd
env
whoami
touch $(date "+%A-%B-%d-%T-%y")
mount | grep ^/dev/ | grep -v /etc | awk '{print \$3}'
git branch
git branch -avv
true
'''
}
}
stage('Prebuild script') {
when {
anyOf{
branch 'develop'
branch 'master'
expression { env.CHANGE_ID != null }
}
}
steps {
sh '''#!/bin/bash
set -xe
. jenkinsjobinfo.sh
curl -f -o jenkins_prebuild_script.sh https://raw.githubusercontent.com/${JENKINS_CI_REPO}/${JENKINS_CI_REPO_BRANCH}/scripts/${ORGANIZATION}_${REPONAME}_lcov_prebuild.sh || true
if [ -f jenkins_prebuild_script.sh ]; then
chmod 755 jenkins_prebuild_script.sh
./jenkins_prebuild_script.sh
fi
'''
}
}
stage('Check if docs were modified') {
when {
anyOf{
expression { env.CHANGE_ID != null }
}
}
steps {
sh '''#!/bin/bash
set -xe
. jenkinsjobinfo.sh
if [ "$ONLY_BUILD_ON_DOCS_MODIFICATION" == "true" ]; then
echo "Starting check to see if docs have been updated."
git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
git fetch origin develop
mergebase=$(git merge-base HEAD remotes/origin/develop)
counter=0
for i in $(git diff --name-only HEAD $mergebase)
do
echo "file is $i"
if [[ $i =~ ^doc/ ]]; then
counter=$((counter+1))
fi
done
if [ "$counter" -eq "0" ]; then
echo "No docs found. Exiting."
# exit 1
echo "export AUTOCANCEL=true" >> jenkinsjobinfo.sh
else
echo "Found $counter docs. Proceeding."
fi
else
echo "Not checking if docs were updated. Always build."
fi
'''
}
}
stage('Determine if the job should exit') {
when {
anyOf{
expression { env.CHANGE_ID != null }
}
}
environment {
// See https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
AUTOCANCEL = """${sh(
returnStdout: true,
script: '#!/bin/bash \n' + 'source jenkinsjobinfo.sh; echo -n "${AUTOCANCEL}"'
)}"""
}
steps {
script {
if (env.AUTOCANCEL == "true") {
currentBuild.result = 'ABORTED'
error("Aborting the build.")
}
}
}
}
// To skip this step, and actually all steps, adjust the job's Filter regex in the Jenkins UI
// (develop|master|PR-.*) will build all branches
// (PR-.*) will build pull requests. Etc.
stage('Build docs') {
when {
anyOf{
branch 'develop'
branch 'master'
expression { env.CHANGE_ID != null }
}
}
steps {
sh '''#!/bin/bash
set -xe
. jenkinsjobinfo.sh
export pythonvirtenvpath=/opt/venvboostdocs
if [ -f ${pythonvirtenvpath}/bin/activate ]; then
source ${pythonvirtenvpath}/bin/activate
fi
# Is there a custom build script? Often not. But let's check:
curl -f -o jenkins_build_script.sh https://raw.githubusercontent.com/${JENKINS_CI_REPO}/${JENKINS_CI_REPO_BRANCH}/scripts/${ORGANIZATION}_${REPONAME}_lcov_build.sh || true
if [ -f jenkins_build_script.sh ]; then
chmod 755 jenkins_build_script.sh
./jenkins_build_script.sh
exit 0
fi
# Otherwise, proceed using standard build steps:
export pythonvirtenvpath=/opt/venv
if [ -f ${pythonvirtenvpath}/bin/activate ]; then
source ${pythonvirtenvpath}/bin/activate
fi
mkdir -p ~/.local/bin
GITHUB_REPO_URL="https://github.com/cppalliance/ci-automation/raw/master"
DIR="scripts"
FILENAME="lcov-jenkins-gcc-13.sh"
URL="${GITHUB_REPO_URL}/$DIR/$FILENAME"
FILE=~/.local/bin/$FILENAME
if [ ! -f "$FILE" ]; then
curl -s -S --retry 10 -L -o $FILE $URL && chmod 755 $FILE
fi
$FILE
'''
}
}
stage('Postbuild script') {
when {
anyOf{
branch 'develop'
branch 'master'
expression { env.CHANGE_ID != null }
}
}
steps {
sh '''#!/bin/bash
set -xe
. jenkinsjobinfo.sh
curl -f -o jenkins_postbuild_script.sh https://raw.githubusercontent.com/${JENKINS_CI_REPO}/${JENKINS_CI_REPO_BRANCH}/scripts/${ORGANIZATION}_${REPONAME}_lcov_postbuild.sh || true
if [ -f jenkins_postbuild_script.sh ]; then
chmod 755 jenkins_postbuild_script.sh
./jenkins_postbuild_script.sh
fi
'''
}
}
stage('Pull requests: Upload to S3') {
when {
anyOf{
expression { env.CHANGE_ID != null }
}
}
environment {
// See https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
REPONAME = """${sh(
returnStdout: true,
script: '#!/bin/bash \n' + 'source jenkinsjobinfo.sh; echo -n "${REPONAME}"'
)}"""
DNSREPONAME = """${sh(
returnStdout: true,
script: '#!/bin/bash \n' + 'source jenkinsjobinfo.sh; echo -n "${DNSREPONAME}"'
)}"""
PRTEST = """${sh(
returnStdout: true,
script: '#!/bin/bash \n' + 'source jenkinsjobinfo.sh; echo -n "${PRTEST}"'
)}"""
PATH_TO_DOCS = """${sh(
returnStdout: true,
script: '#!/bin/bash \n' + 'source jenkinsjobinfo.sh; echo -n "${PATH_TO_DOCS}"'
)}"""
DIFF2HTML = """${sh(
returnStdout: true,
script: '#!/bin/bash \n' + 'source jenkinsjobinfo.sh; echo -n "${DIFF2HTML}"'
)}"""
}
steps {
withAWS(region:'us-east-1', credentials: 'cppalliance-bot-aws-user') {
s3Upload(bucket:"cppalliance-previews", path:"${DNSREPONAME}/${CHANGE_ID}/genhtml/", workingDir: "genhtml" , includePathPattern:"**")
s3Upload(bucket:"cppalliance-previews", path:"${DNSREPONAME}/${CHANGE_ID}/gcovr/", workingDir: "gcovr" , includePathPattern:"**")
}
script {
commenttext = "GCOVR code coverage report [https://${env.CHANGE_ID}.${env.DNSREPONAME}.${env.PRTEST}.cppalliance.org/gcovr/index.html](https://${env.CHANGE_ID}.${env.DNSREPONAME}.${env.PRTEST}.cppalliance.org/gcovr/index.html)\nLCOV code coverage report [https://${env.CHANGE_ID}.${env.DNSREPONAME}.${env.PRTEST}.cppalliance.org/genhtml/index.html](https://${env.CHANGE_ID}.${env.DNSREPONAME}.${env.PRTEST}.cppalliance.org/genhtml/index.html)\nCoverage Diff [https://${env.CHANGE_ID}.${env.DNSREPONAME}.${env.PRTEST}.cppalliance.org/gcovr/coverage_diff.txt](https://${env.CHANGE_ID}.${env.DNSREPONAME}.${env.PRTEST}.cppalliance.org/gcovr/coverage_diff.txt)"
pullRequest.comment(commenttext)
}
}
}
stage('Post Diagnostics') {
steps {
sh '''#!/bin/bash
set -x
# not set -e. errors may occur in diagnostics
cat jenkinsjobinfo.sh
. jenkinsjobinfo.sh
ls -al
cat /etc/os-release
pwd
env
whoami
touch $(date "+%A-%B-%d-%T-%y")
mount | grep ^/dev/ | grep -v /etc | awk '{print \$3}'
git branch
git branch -avv
true
'''
}
}
}
post {
always {
echo 'This will always run'
}
success {
echo 'This will run only if successful'
// no email on success
// mail bcc: '', body: "<b>Example</b><br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL of the build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "SUCCESS CI: Project name -> ${env.JOB_NAME}", to: "[email protected]";
}
failure {
echo 'This will run only if failure'
mail bcc: '', body: "<b>Example</b><br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL of the build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "ERROR CI: Project name -> ${env.JOB_NAME}", to: "[email protected]";
}
unstable {
echo 'This will run only if the run was marked as unstable'
mail bcc: '', body: "<b>Example</b><br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL of the build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "UNSTABLE STATUS CI: Project name -> ${env.JOB_NAME}", to: "[email protected]";
}
changed {
echo 'This will run only if the state of the Pipeline has changed'
echo 'For example, if the Pipeline was previously failing but is now successful'
// no email on changed status
// mail bcc: '', body: "<b>Example</b><br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL of the build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "CHANGED STATUS CI: Project name -> ${env.JOB_NAME}", to: "[email protected]";
}
}
}