-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebsite_v2_docs_1
326 lines (283 loc) · 12.9 KB
/
website_v2_docs_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
pipeline {
// agent {
// node {
// label 'jenkinspool1'
// }
// }
agent {
docker {
image 'cppalliance/boost_superproject_build:24.04-v3'
// label 'jenkinspool1'
}
}
stages {
stage('Preclean Workspace') {
steps {
sh """#!/bin/bash
set -xe
rm -rf * .*
"""
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`)
# If this jenkinsfile will be used for multiple repos then it should use the general form of DNSREPONAME:
# DNSREPONAME=$(echo $REPONAME | tr '_' '-')
# However at the moment it's only used by website-v2-docs. For the time being, the customization may be placed here:
DNSREPONAME="site-docs"
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=prtest2" >> jenkinsjobinfo.sh
echo "export REPONAME=${REPONAME}" >> jenkinsjobinfo.sh
echo "export DNSREPONAME=${DNSREPONAME}" >> jenkinsjobinfo.sh
echo "export ORGANIZATION=${ORGANIZATION}" >> 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}_prebuild.sh || true
if [ -f jenkins_prebuild_script.sh ]; then
chmod 755 jenkins_prebuild_script.sh
./jenkins_prebuild_script.sh
fi
'''
}
}
// 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}_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/venvboostdocs
if [ -f ${pythonvirtenvpath}/bin/activate ]; then
source ${pythonvirtenvpath}/bin/activate
fi
echo "env"
env
echo "pwd"
pwd
echo "home is $HOME"
echo "ls -al HOME"
ls -al $HOME
echo "ls ~/"
ls -al ~/
mkdir -p ~/.nvm_${REPONAME}_antora
export NODE_VERSION=18.18.1
# The container has a pre-installed nodejs. Overwrite those again.
export NVM_BIN="$HOME/.nvm_${REPONAME}_antora/versions/node/v18.18.1/bin"
export NVM_DIR=$HOME/.nvm_${REPONAME}_antora
export NVM_INC=$HOME/.nvm_${REPONAME}_antora/versions/node/v18.18.1/include/node
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
export NVM_DIR=$HOME/.nvm_${REPONAME}_antora
. "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
. "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION}
. "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
export PATH="$HOME/.nvm_${REPONAME}_antora/versions/node/v${NODE_VERSION}/bin/:${PATH}"
node --version
npm --version
npm install [email protected]
npm install @mermaid-js/[email protected]
npm ci
./build.sh ${CHANGE_TARGET}
rm build/index.html || true
curl -f -o build/index.html https://raw.githubusercontent.com/${JENKINS_CI_REPO}/${JENKINS_CI_REPO_BRANCH}/scripts/${ORGANIZATION}_${REPONAME}_index.html
cat build/index.html
'''
}
}
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}_postbuild.sh || true
if [ -f jenkins_postbuild_script.sh ]; then
chmod 755 jenkins_postbuild_script.sh
./jenkins_postbuild_script.sh
fi
'''
}
}
stage('Main branches: Upload to S3') {
when {
anyOf{
branch 'develop'
branch 'master'
}
}
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}"'
)}"""
}
steps {
withAWS(region:'us-east-1', credentials: 'cppalliance-bot-aws-user') {
sh '''#!/bin/bash
set -xe
aws s3 rm --recursive s3://cppalliance-websites/${BRANCH_NAME}.${DNSREPONAME}.cpp.al/
'''
s3Upload(bucket:"cppalliance-websites", path:"${BRANCH_NAME}.${DNSREPONAME}.cpp.al", workingDir: "build", includePathPattern:"**")
}
}
}
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}"'
)}"""
}
steps {
withAWS(region:'us-east-1', credentials: 'cppalliance-bot-aws-user') {
sh '''#!/bin/bash
set -xe
aws s3 rm --recursive s3://cppalliance-previews/${DNSREPONAME}/${CHANGE_ID}/
'''
s3Upload(bucket:"cppalliance-previews", path:"${DNSREPONAME}/${CHANGE_ID}/", workingDir: "build" , includePathPattern:"**")
}
script {
commenttext = "An automated preview of the documentation is available at [https://${env.CHANGE_ID}.${env.DNSREPONAME}.${env.PRTEST}.cppalliance.org/index.html](https://${env.CHANGE_ID}.${env.DNSREPONAME}.${env.PRTEST}.cppalliance.org/index.html)"
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]";
}
}
}