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