Move all doc verfication to docs-verify-rtd-*
[releng.git] / jjb / global / releng-macros.yml
1 ---
2 # Releng macros
3 #
4 # NOTE: make sure macros are listed in execution ordered.
5 #
6 # 1. parameters/properties
7 # 2. scm
8 # 3. triggers
9 # 4. wrappers
10 # 5. prebuilders (maven only, configured like Builders)
11 # 6. builders (maven, freestyle, matrix, etc..)
12 # 7. postbuilders (maven only, configured like Builders)
13 # 8. publishers/reporters/notifications
14
15 - parameter:
16     name: project-parameter
17     parameters:
18       - string:
19           name: PROJECT
20           default: '{project}'
21           description: "JJB configured PROJECT parameter to identify an opnfv Gerrit project"
22       - string:
23           name: GS_BASE
24           default: artifacts.opnfv.org/$PROJECT
25           description: "URL to Google Storage."
26       - string:
27           name: GS_BASE_PROXY
28           default: build.opnfv.org/artifacts.opnfv.org/$PROJECT
29           description: "URL to Google Storage proxy"
30       - string:
31           name: BRANCH
32           default: '{branch}'
33           description: "JJB configured BRANCH parameter (e.g. master, stable/danube)"
34       - string:
35           name: GERRIT_BRANCH
36           default: '{branch}'
37           description: "JJB configured GERRIT_BRANCH parameter (deprecated)"
38
39 - property:
40     name: logrotate-default
41     properties:
42       - build-discarder:
43           days-to-keep: 60
44           num-to-keep: 200
45           artifact-days-to-keep: 60
46           artifact-num-to-keep: 200
47
48 - scm:
49     name: git-scm
50     scm:
51       - git: &git-scm-defaults
52           credentials-id: '$SSH_CREDENTIAL_ID'
53           url: '$GIT_BASE'
54           branches:
55             - 'origin/$BRANCH'
56           timeout: 15
57
58 - scm:
59     name: git-scm-gerrit
60     scm:
61       - git:
62           choosing-strategy: 'gerrit'
63           refspec: '$GERRIT_REFSPEC'
64           <<: *git-scm-defaults
65 - scm:
66     name: git-scm-with-submodules
67     scm:
68       - git:
69           credentials-id: '$SSH_CREDENTIAL_ID'
70           url: '$GIT_BASE'
71           refspec: ''
72           branches:
73             - 'refs/heads/{branch}'
74           skip-tag: true
75           wipe-workspace: true
76           submodule:
77             recursive: true
78             timeout: 20
79 - trigger:
80     name: 'daily-trigger-disabled'
81     triggers:
82       - timed: ''
83
84 - trigger:
85     name: 'weekly-trigger-disabled'
86     triggers:
87       - timed: ''
88
89 - trigger:
90     name: gerrit-trigger-patchset-created
91     triggers:
92       - gerrit:
93           server-name: 'gerrit.opnfv.org'
94           trigger-on:
95             - patchset-created-event:
96                 exclude-drafts: 'false'
97                 exclude-trivial-rebase: 'false'
98                 exclude-no-code-change: 'false'
99             - draft-published-event
100             - comment-added-contains-event:
101                 comment-contains-value: 'recheck'
102             - comment-added-contains-event:
103                 comment-contains-value: 'reverify'
104           projects:
105             - project-compare-type: 'ANT'
106               project-pattern: '{project}'
107               branches:
108                 - branch-compare-type: 'ANT'
109                   branch-pattern: '**/{branch}'
110               file-paths:
111                 - compare-type: 'ANT'
112                   pattern: '{files}'
113           skip-vote:
114             successful: false
115             failed: false
116             unstable: false
117             notbuilt: false
118
119 - trigger:
120     name: gerrit-trigger-change-merged
121     triggers:
122       - gerrit:
123           server-name: 'gerrit.opnfv.org'
124           trigger-on:
125             - change-merged-event
126             - comment-added-contains-event:
127                 comment-contains-value: 'remerge'
128           projects:
129             - project-compare-type: 'ANT'
130               project-pattern: '{project}'
131               branches:
132                 - branch-compare-type: 'ANT'
133                   branch-pattern: '**/{branch}'
134               file-paths:
135                 - compare-type: 'ANT'
136                   pattern: '{files}'
137
138 - trigger:
139     name: 'experimental'
140     triggers:
141       - gerrit:
142           server-name: 'gerrit.opnfv.org'
143           trigger-on:
144             - comment-added-contains-event:
145                 comment-contains-value: 'check-experimental'
146           projects:
147             - project-compare-type: 'ANT'
148               project-pattern: '{project}'
149               branches:
150                 - branch-compare-type: 'ANT'
151                   branch-pattern: '**/{branch}'
152               file-paths:
153                 - compare-type: 'ANT'
154                   pattern: '{files}'
155           skip-vote:
156             successful: true
157             failed: true
158             unstable: true
159             notbuilt: true
160
161 - wrapper:
162     name: ssh-agent-wrapper
163     wrappers:
164       - ssh-agent-credentials:
165           users:
166             - 'd42411ac011ad6f3dd2e1fa34eaa5d87f910eb2e'
167
168 - wrapper:
169     name: build-timeout
170     wrappers:
171       - timeout:
172           timeout: '{timeout}'
173           timeout-var: 'BUILD_TIMEOUT'
174           fail: true
175
176 - wrapper:
177     name: fix-workspace-permissions
178     wrappers:
179       - pre-scm-buildstep:
180           - shell: |
181              #!/bin/bash
182              sudo chown -R $USER:$USER $WORKSPACE || exit 1
183
184 - builder:
185     name: upload-under-review-docs-to-opnfv-artifacts
186     builders:
187       - shell: |
188           #!/bin/bash
189           set -o errexit
190           set -o pipefail
191           set -o xtrace
192           export PATH=$PATH:/usr/local/bin/
193
194           [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
195           [[ -d docs_output ]] || exit 0
196
197           echo
198           echo "###########################"
199           echo "UPLOADING DOCS UNDER REVIEW"
200           echo "###########################"
201           echo
202
203           gs_base="artifacts.opnfv.org/$PROJECT/review"
204           gs_path="$gs_base/$GERRIT_CHANGE_NUMBER"
205           local_path="upload/$GERRIT_CHANGE_NUMBER"
206
207           mkdir -p upload
208           mv docs/_build/html/ "$local_path"
209           gsutil -m cp -r "$local_path" "gs://$gs_base"
210
211           gsutil -m setmeta \
212               -h "Content-Type:text/html" \
213               -h "Cache-Control:private, max-age=0, no-transform" \
214               "gs://$gs_path"/**.html > /dev/null 2>&1
215
216           echo "Document link(s):" >> gerrit_comment.txt
217           find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
218               sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt
219
220 # To take advantage of this macro, have your build write
221 # out the file 'gerrit_comment.txt' with information to post
222 # back to gerrit and include this macro in the list of builders.
223 - builder:
224     name: report-build-result-to-gerrit
225     builders:
226       - shell: |
227           #!/bin/bash
228           set -o errexit
229           set -o pipefail
230           set -o xtrace
231           export PATH=$PATH:/usr/local/bin/
232           if [[ -e gerrit_comment.txt ]] ; then
233               echo
234               echo "posting review comment to gerrit..."
235               echo
236               cat gerrit_comment.txt
237               echo
238               ssh -p 29418 gerrit.opnfv.org \
239                   "gerrit review -p $GERRIT_PROJECT \
240                    -m '$(cat gerrit_comment.txt)' \
241                    $GERRIT_PATCHSET_REVISION \
242                    --notify NONE"
243           fi
244
245 - builder:
246     name: remove-old-docs-from-opnfv-artifacts
247     builders:
248       - shell: |
249           #!/bin/bash
250           set -o errexit
251           set -o pipefail
252           set -o xtrace
253           export PATH=$PATH:/usr/local/bin/
254
255           [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
256
257           gs_path="artifacts.opnfv.org/$PROJECT/review/$GERRIT_CHANGE_NUMBER"
258
259           if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
260               echo
261               echo "Deleting Out-of-dated Documents..."
262               gsutil -m rm -r "gs://$gs_path"
263           fi
264           gs_path="artifacts.opnfv.org/review/$GERRIT_CHANGE_NUMBER"
265
266           if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
267               echo
268               echo "Deleting Out-of-dated Documents..."
269               gsutil -m rm -r "gs://$gs_path"
270           fi
271
272 - builder:
273     name: build-and-upload-artifacts-json-api
274     builders:
275       - shell: |
276           #!/bin/bash
277           set -o errexit
278           set -o pipefail
279           export PATH=$PATH:/usr/local/bin/
280
281           virtualenv -p python2.7 $WORKSPACE/releng_artifacts
282           source $WORKSPACE/releng_artifacts/bin/activate
283
284           # install python packages
285           pip install google-api-python-client
286
287           # generate and upload index file
288           echo "Generating Artifacts API ..."
289           python $WORKSPACE/utils/opnfv-artifacts.py > index.json
290           gsutil cp index.json gs://artifacts.opnfv.org/index.json
291
292           deactivate
293
294 - builder:
295     name: lint-python-code
296     builders:
297       - shell: |
298           #!/bin/bash
299           set -o errexit
300           set -o pipefail
301           set -o xtrace
302           export PATH=$PATH:/usr/local/bin/
303
304           virtualenv -p python2.7 $WORKSPACE/releng_flake8
305           source $WORKSPACE/releng_flake8/bin/activate
306
307           # install python packages
308           pip install "flake8==2.6.2"
309
310           # generate and upload lint log
311           echo "Running flake8 code on $PROJECT ..."
312
313           # Get number of flake8 violations. If none, this will be an
314           # empty string: ""
315           FLAKE_COUNT="$(find . \
316               -path './releng_flake8' -prune -o \
317               -path './.tox' -prune -o \
318               -type f -name "*.py" -print | \
319               xargs flake8 --exit-zero -qq --count 2>&1)"
320
321           # Ensure we start with a clean environment
322           rm -f lint.log
323
324           if [ ! -z $FLAKE_COUNT ]; then
325             echo "Flake8 Violations: $FLAKE_COUNT" > lint.log
326             find . \
327                 -path './releng_flake8' -prune -o \
328                 -path './.tox' -prune -o \
329                 -type f -name "*.py" -print | \
330                 xargs flake8 --exit-zero --first >> violation.log
331             SHOWN=$(wc -l violation.log | cut -d' ' -f1)
332             echo -e "First $SHOWN shown\n---" >> lint.log
333             cat violation.log >> lint.log
334             sed -r -i '4,$s/^/ /g' lint.log
335             rm violation.log
336           fi
337
338           deactivate
339
340 - builder:
341     name: report-lint-result-to-gerrit
342     builders:
343       - shell: |
344           #!/bin/bash
345           set -o errexit
346           set -o pipefail
347           set -o xtrace
348           export PATH=$PATH:/usr/local/bin/
349
350           # If no violations were found, no lint log will exist.
351           if [[ -e lint.log ]] ; then
352               echo -e "\nposting linting report to gerrit...\n"
353
354               cat lint.log
355               echo
356
357               ssh -p 29418 gerrit.opnfv.org \
358                   "gerrit review -p $GERRIT_PROJECT \
359                    -m \"$(cat lint.log)\" \
360                    $GERRIT_PATCHSET_REVISION \
361                    --notify NONE"
362
363               exit 1
364           fi
365
366 - builder:
367     name: upload-review-docs
368     builders:
369       - upload-under-review-docs-to-opnfv-artifacts
370       - report-build-result-to-gerrit
371
372 - builder:
373     name: check-bash-syntax
374     builders:
375       - shell: "find . -name '*.sh' | xargs bash -n"
376
377 - builder:
378     name: lint-yaml-code
379     builders:
380       - shell: |
381           #!/bin/bash
382           set -o errexit
383           set -o pipefail
384           set -o xtrace
385           export PATH=$PATH:/usr/local/bin/
386
387           # install python packages
388           pip install "yamllint==1.6.0"
389
390           # generate and upload lint log
391           echo "Running yaml code on $PROJECT ..."
392
393           # Ensure we start with a clean environment
394           rm -f yaml-violation.log lint.log
395
396           # Get number of yaml violations. If none, this will be an
397           # empty string: ""
398           find . \
399               -type f -name "*.yml" -print \
400               -o -name "*.yaml" -print | \
401               xargs yamllint > yaml-violation.log || true
402
403           if [ -s "yaml-violation.log" ]; then
404             SHOWN=$(cat yaml-violation.log| grep -v "^$" |wc -l)
405             echo -e "First $SHOWN shown\n---" > lint.log
406             cat yaml-violation.log >> lint.log
407             sed -r -i '4,$s/^/ /g' lint.log
408           fi
409
410 - builder:
411     name: clean-workspace
412     builders:
413       - shell: |
414           #!/bin/bash
415           set -o errexit
416           set -o nounset
417           set -o pipefail
418           sudo /bin/rm -rf "$WORKSPACE"
419
420 - builder:
421     name: clean-workspace-log
422     builders:
423       - shell: |
424           find $WORKSPACE -type f -name '*.log' | xargs rm -f
425
426 - publisher:
427     name: archive-artifacts
428     publishers:
429       - archive:
430           artifacts: '{artifacts}'
431           allow-empty: true
432           fingerprint: true
433           latest-only: true
434
435 - publisher:
436     name: publish-coverage
437     publishers:
438       - cobertura:
439           report-file: "coverage.xml"
440           only-stable: "true"
441           health-auto-update: "false"
442           stability-auto-update: "false"
443           zoom-coverage-chart: "true"
444           targets:
445             - files:
446                 healthy: 10
447                 unhealthy: 20
448                 failing: 30
449             - method:
450                 healthy: 50
451                 unhealthy: 40
452                 failing: 30
453
454 # The majority of the email-ext plugin options are set to the default
455 # for this macro so they can be managed through Jenkins' global
456 # settings.
457 - publisher:
458     name: email-jenkins-admins-on-failure
459     publishers:
460       - email-ext:
461           content-type: text
462           attach-build-log: true
463           compress-log: true
464           always: false
465           failure: true
466           send-to:
467             - recipients