031e24070bd4a68ceabb54dc4dd44a0a20afea68
[releng.git] / jjb / global / releng-macros.yaml
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       - string:
39           name: GERRIT_REFSPEC
40           default: 'refs/heads/{branch}'
41           description: "Default refspec needed for manually triggering."
42
43 ##
44 # Reporting Deployment Results
45 #
46 # To report deployment results to
47 # http://testresults.opnfv.org/test/#/deployresults, add the following
48 # parameters, builders, and publishers to a deployment job:
49 #
50 #   parameters:
51 #    - testapi-parameter
52 #
53 #   builders:
54 #    - track-begin-timestamp
55 #
56 #   publishers:
57 #    - report-provision-result
58 #
59 # Note: The following string parameter must also exist, as they are used
60 #       when reporting the provision result:
61 #
62 #  * INSTALLER
63 #  * INSTALLER_VERSION
64 #  * DEPLOY_SCENARIO
65 #
66 # most installers include these but you should verify first before
67 # adding the publisher, otherwise the deployment build may be marked
68 # unstable.
69 #
70 ##
71 - parameter:
72     name: testapi-parameter
73     parameters:
74       - string:
75           name: TESTAPI_URL
76           default: 'http://testresults.opnfv.org/test/api/v1'
77           description: "Default TestAPI URL, currently using v1"
78       - string:
79           name: INSTALLER_VERSION
80           default: 'master'
81           description: "Installer release version"
82       - string:
83           name: UPSTREAM_JOB_NAME
84           default: ''
85           description: "Parent job name in Jenkins"
86       - string:
87           name: UPSTREAM_BUILD_ID
88           default: ''
89           description: "Parent job build_id in Jenkins"
90
91 - property:
92     name: logrotate-default
93     properties:
94       - build-discarder:
95           days-to-keep: 60
96           num-to-keep: 200
97           artifact-days-to-keep: 60
98           artifact-num-to-keep: 200
99
100 - scm:
101     name: git-scm
102     scm:
103       - git: &git-scm-defaults
104           credentials-id: 'd42411ac011ad6f3dd2e1fa34eaa5d87f910eb2e'
105           url: '$GIT_BASE'
106           branches:
107             - 'origin/$BRANCH'
108           timeout: 15
109           per-build-tag: false
110           skip-tag: true
111           shallow-clone: false
112           use-author: false
113           ignore-notify: false
114           wipe-workspace: true
115           prune: false
116
117 - scm:
118     name: git-scm-gerrit
119     scm:
120       - git:
121           choosing-strategy: 'gerrit'
122           refspec: '$GERRIT_REFSPEC'
123           <<: *git-scm-defaults
124
125 - scm:
126     name: git-scm-gerrit-with-submodules
127     scm:
128       - git:
129           choosing-strategy: 'gerrit'
130           refspec: '$GERRIT_REFSPEC'
131           submodule:
132             recursive: true
133             timeout: 20
134           <<: *git-scm-defaults
135 - scm:
136     name: git-scm-with-submodules
137     scm:
138       - git:
139           credentials-id: 'd42411ac011ad6f3dd2e1fa34eaa5d87f910eb2e'
140           url: '$GIT_BASE'
141           refspec: ''
142           branches:
143             - 'refs/heads/{branch}'
144           per-build-tag: false
145           skip-tag: true
146           wipe-workspace: true
147           submodule:
148             recursive: true
149             timeout: 20
150
151 - scm:
152     name: git-scm-openstack
153     scm:
154       - git: &git-scm-openstack-defaults
155           per-build-tag: false
156           skip-tag: true
157           url: '$GIT_BASE'
158           branches:
159             - 'origin/$BRANCH'
160           timeout: 15
161
162 - trigger:
163     name: 'daily-trigger-disabled'
164     triggers:
165       - timed: ''
166
167 - trigger:
168     name: 'weekly-trigger-disabled'
169     triggers:
170       - timed: ''
171
172 - trigger:
173     name: gerrit-trigger-patchset-created
174     triggers:
175       - gerrit:
176           server-name: 'gerrit.opnfv.org'
177           trigger-on:
178             - patchset-created-event:
179                 exclude-drafts: 'false'
180                 exclude-trivial-rebase: 'false'
181                 exclude-no-code-change: 'false'
182             - draft-published-event
183             - comment-added-contains-event:
184                 comment-contains-value: 'recheck'
185             - comment-added-contains-event:
186                 comment-contains-value: 'reverify'
187           projects:
188             - project-compare-type: 'ANT'
189               project-pattern: '{project}'
190               branches:
191                 - branch-compare-type: 'ANT'
192                   branch-pattern: '**/{branch}'
193               file-paths:
194                 - compare-type: 'ANT'
195                   pattern: '{files}'
196           skip-vote:
197             successful: false
198             failed: false
199             unstable: false
200             notbuilt: false
201
202 - trigger:
203     name: gerrit-trigger-patchset-approved
204     triggers:
205       - gerrit:
206           server-name: 'gerrit.opnfv.org'
207           trigger-on:
208             - comment-added-event:
209                 approval-category: 'CRVW'
210                 approval-value: 2
211             - comment-added-contains-event:
212                 comment-contains-value: 'gate'
213           projects:
214             - project-compare-type: 'ANT'
215               project-pattern: '{project}'
216               branches:
217                 - branch-compare-type: 'ANT'
218                   branch-pattern: '**/{branch}'
219               file-paths:
220                 - compare-type: 'ANT'
221                   pattern: '{files}'
222           skip-vote:
223             successful: false
224             failed: false
225             unstable: false
226             notbuilt: false
227
228 - trigger:
229     name: gerrit-trigger-change-merged
230     triggers:
231       - gerrit:
232           server-name: 'gerrit.opnfv.org'
233           trigger-on:
234             - change-merged-event
235             - comment-added-contains-event:
236                 comment-contains-value: 'remerge'
237           projects:
238             - project-compare-type: 'ANT'
239               project-pattern: '{project}'
240               branches:
241                 - branch-compare-type: 'ANT'
242                   branch-pattern: '**/{branch}'
243               file-paths:
244                 - compare-type: 'ANT'
245                   pattern: '{files}'
246
247 - trigger:
248     name: gerrit-trigger-tag-created
249     triggers:
250       - gerrit:
251           server-name: 'gerrit.opnfv.org'
252           trigger-on:
253             - ref-updated-event
254           projects:
255             - project-compare-type: 'ANT'
256               project-pattern: '{project}'
257               branches:
258                 - branch-compare-type: 'ANT'
259                   branch-pattern: 'refs/tags/**'
260
261 - trigger:
262     name: 'experimental'
263     triggers:
264       - gerrit:
265           server-name: 'gerrit.opnfv.org'
266           trigger-on:
267             - comment-added-contains-event:
268                 comment-contains-value: 'check-experimental'
269           projects:
270             - project-compare-type: 'ANT'
271               project-pattern: '{project}'
272               branches:
273                 - branch-compare-type: 'ANT'
274                   branch-pattern: '**/{branch}'
275               file-paths:
276                 - compare-type: 'ANT'
277                   pattern: '{files}'
278           skip-vote:
279             successful: true
280             failed: true
281             unstable: true
282             notbuilt: true
283
284 - wrapper:
285     name: ssh-agent-wrapper
286     wrappers:
287       - ssh-agent-credentials:
288           users:
289             - 'd42411ac011ad6f3dd2e1fa34eaa5d87f910eb2e'
290
291 - wrapper:
292     name: build-timeout
293     wrappers:
294       - timeout:
295           timeout: '{timeout}'
296           timeout-var: 'BUILD_TIMEOUT'
297           fail: true
298
299 - wrapper:
300     name: fix-workspace-permissions
301     wrappers:
302       - pre-scm-buildstep:
303           - shell: |
304              #!/bin/bash
305              sudo chown -R $USER:$USER $WORKSPACE || exit 1
306
307 - builder:
308     name: upload-under-review-docs-to-opnfv-artifacts
309     builders:
310       - shell: |
311           #!/bin/bash
312           set -o errexit
313           set -o pipefail
314           set -o xtrace
315           export PATH=$PATH:/usr/local/bin/
316
317           [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
318           [[ -d docs/_build/ ]] || exit 0
319
320           echo
321           echo "###########################"
322           echo "UPLOADING DOCS UNDER REVIEW"
323           echo "###########################"
324           echo
325
326           gs_base="artifacts.opnfv.org/$PROJECT/review"
327           gs_path="$gs_base/$GERRIT_CHANGE_NUMBER"
328           local_path="upload/$GERRIT_CHANGE_NUMBER"
329
330           mkdir -p upload
331           mv docs/_build/html/ "$local_path"
332           gsutil -m cp -r "$local_path" "gs://$gs_base"
333
334           gsutil -m setmeta \
335               -h "Content-Type:text/html" \
336               -h "Cache-Control:private, max-age=0, no-transform" \
337               "gs://$gs_path"/**.html > /dev/null 2>&1
338
339           echo "Document link(s):" >> gerrit_comment.txt
340           find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
341               sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt
342
343 # To take advantage of this macro, have your build write
344 # out the file 'gerrit_comment.txt' with information to post
345 # back to gerrit and include this macro in the list of builders.
346 - builder:
347     name: report-build-result-to-gerrit
348     builders:
349       - shell: |
350           #!/bin/bash
351           set -o errexit
352           set -o pipefail
353           set -o xtrace
354           export PATH=$PATH:/usr/local/bin/
355           if [[ -e gerrit_comment.txt ]] ; then
356               echo
357               echo "posting review comment to gerrit..."
358               echo
359               cat gerrit_comment.txt
360               echo
361               ssh -p 29418 gerrit.opnfv.org \
362                   "gerrit review -p $GERRIT_PROJECT \
363                    -m '$(cat gerrit_comment.txt)' \
364                    $GERRIT_PATCHSET_REVISION \
365                    --notify NONE"
366           fi
367
368 - builder:
369     name: remove-old-docs-from-opnfv-artifacts
370     builders:
371       - shell: |
372           #!/bin/bash
373           set -o errexit
374           set -o pipefail
375           set -o xtrace
376           export PATH=$PATH:/usr/local/bin/
377
378           [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
379
380           gs_path="artifacts.opnfv.org/$PROJECT/review/$GERRIT_CHANGE_NUMBER"
381
382           if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
383               echo
384               echo "Deleting Out-of-dated Documents..."
385               gsutil -m rm -r "gs://$gs_path"
386           fi
387           gs_path="artifacts.opnfv.org/review/$GERRIT_CHANGE_NUMBER"
388
389           if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
390               echo
391               echo "Deleting Out-of-dated Documents..."
392               gsutil -m rm -r "gs://$gs_path"
393           fi
394
395 - builder:
396     name: upload-review-docs
397     builders:
398       - upload-under-review-docs-to-opnfv-artifacts
399       - report-build-result-to-gerrit
400
401 - builder:
402     name: lint-init
403     builders:
404       - shell: |
405           #!/bin/bash
406           # Ensure we start with a clean environment
407           rm -f bash-violation.log python-violation.log yaml-violation.log violation.log
408           git --no-pager diff --diff-filter=MCRAT --name-only HEAD^1 > modified_files
409
410 - builder:
411     name: lint-report
412     builders:
413       - shell: |
414           #!/bin/bash
415           if [[ -s violation.log ]]; then
416               cat violation.log
417               echo "Reporting lint result...."
418               set -x
419               msg="Found syntax error and/or coding style violation(s) in the files modified by your patchset."
420               sed -i -e "1s#^#${msg}\n\n#" violation.log
421               cmd="gerrit review -p $GERRIT_PROJECT -m \"$(cat violation.log)\" $GERRIT_PATCHSET_REVISION --notify NONE"
422               ssh -p 29418 gerrit.opnfv.org "$cmd"
423
424               # Make sure the caller job failed
425               exit 1
426           fi
427
428 - builder:
429     name: lint-bash-code
430     builders:
431       - shell: |
432           #!/bin/bash
433           echo "Checking bash code..."
434           for f in $(egrep '\.sh$' modified_files)
435           do
436               bash -n "$f" 2>> bash-violation.log
437           done
438           if [[ -s bash-violation.log ]]; then
439               echo -e "Bash syntax error(s)\n---" >> violation.log
440               sed -e 's/^/ /g' bash-violation.log >> violation.log
441           fi
442
443 - builder:
444     name: lint-python-code
445     builders:
446       - shell: |
447           #!/bin/bash
448
449           sudo apt-get -o DPkg::Lock::Timeout=300 update && \
450           sudo DEBIAN_FRONTEND=noninteractive apt-get \
451             -o DPkg::Lock::Timeout=300 dist-upgrade -y
452           sudo DEBIAN_FRONTEND=noninteractive \
453           apt-get -o DPkg::Lock::Timeout=300 install flake8 -y
454
455           echo "Checking python code..."
456           for f in $(egrep '\.py$' modified_files)
457           do
458               flake8 "$f" >> python-violation.log
459           done
460           if [[ -s python-violation.log ]]; then
461               echo -e "Python violation(s)\n---" >> violation.log
462               sed -e 's/^/ /g' python-violation.log >> violation.log
463           fi
464
465 - builder:
466     name: lint-yaml-code
467     builders:
468       - shell: |
469           #!/bin/bash
470
471           sudo apt-get -o DPkg::Lock::Timeout=300 update && \
472           sudo DEBIAN_FRONTEND=noninteractive apt-get \
473             -o DPkg::Lock::Timeout=300 dist-upgrade -y
474           sudo DEBIAN_FRONTEND=noninteractive \
475           apt-get -o DPkg::Lock::Timeout=300 install yamllint -y
476
477           echo "Checking yaml file..."
478           for f in $(egrep '\.ya?ml$' modified_files)
479           do
480               yamllint "$f" >> yaml-violation.log
481           done
482           if [[ -s yaml-violation.log ]]; then
483               echo -e "YAML violation(s)\n---" >> violation.log
484               sed -e 's/^/ /g' yaml-violation.log >> violation.log
485           fi
486
487 - builder:
488     name: lint-all-code
489     builders:
490       - lint-init
491       - lint-bash-code
492       - lint-python-code
493       - lint-yaml-code
494       - lint-report
495
496 - builder:
497     name: clean-workspace
498     builders:
499       - shell: |
500           #!/bin/bash
501           set -o errexit
502           set -o nounset
503           set -o pipefail
504           sudo /bin/rm -rf "$WORKSPACE"
505
506 - builder:
507     name: clean-workspace-log
508     builders:
509       - shell: |
510           find $WORKSPACE -type f -name '*.log' | xargs rm -f
511
512 - builder:
513     name: track-begin-timestamp
514     builders:
515       - shell: |
516           echo "export TIMESTAMP_START="\'`date '+%Y-%m-%d %H:%M:%S.%3N'`\' > $WORKSPACE/installer_track.sh
517
518 - publisher:
519     name: archive-artifacts
520     publishers:
521       - archive:
522           artifacts: '{artifacts}'
523           allow-empty: true
524           fingerprint: true
525           latest-only: true
526
527 - publisher:
528     name: publish-coverage
529     publishers:
530       - cobertura:
531           report-file: "coverage.xml"
532           only-stable: "true"
533           health-auto-update: "false"
534           stability-auto-update: "false"
535           zoom-coverage-chart: "true"
536           targets:
537             - files:
538                 healthy: 10
539                 unhealthy: 20
540                 failing: 30
541             - method:
542                 healthy: 50
543                 unhealthy: 40
544                 failing: 30
545
546 # The majority of the email-ext plugin options are set to the default
547 # for this macro so they can be managed through Jenkins' global
548 # settings.
549 - publisher:
550     name: email-jenkins-admins-on-failure
551     publishers:
552       - email-ext:
553           content-type: text
554           attach-build-log: true
555           compress-log: true
556           always: false
557           failure: true
558           send-to:
559             - recipients
560
561 - publisher:
562     name: 'report-provision-result'
563     publishers:
564       - postbuildscript:
565           builders:
566             - role: BOTH
567               build-on:
568                 - SUCCESS
569               build-steps:
570                 - shell: |
571                     echo "export PROVISION_RESULT=PASS" >> $WORKSPACE/installer_track.sh
572                     echo "export INSTALLER=$INSTALLER_TYPE" >> $WORKSPACE/installer_track.sh
573                     echo "export TIMESTAMP_END="\'`date '+%Y-%m-%d %H:%M:%S.%3N'`\' >> $WORKSPACE/installer_track.sh
574                 - shell:
575                     !include-raw: installer-report.sh
576           mark-unstable-if-failed: true
577       - postbuildscript:
578           builders:
579             - role: BOTH
580               build-on:
581                 - ABORTED
582                 - FAILURE
583                 - NOT_BUILT
584                 - UNSTABLE
585               build-steps:
586                 - shell: |
587                     echo "export PROVISION_RESULT=FAIL" >> $WORKSPACE/installer_track.sh
588                     echo "export INSTALLER=$INSTALLER_TYPE" >> $WORKSPACE/installer_track.sh
589                     echo "export TIMESTAMP_END="\'`date '+%Y-%m-%d %H:%M:%S.%3N'`\' >> $WORKSPACE/installer_track.sh
590                 - shell:
591                     !include-raw: installer-report.sh
592           mark-unstable-if-failed: true