6fdb4caf4d84a716686483b8790ed68f76f119a1
[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: 'tests/**'
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 - builder:
168     name: build-html-and-pdf-docs-output
169     builders:
170         - shell: |
171             #!/bin/bash
172             set -o errexit
173             set -o xtrace
174             export PATH=$PATH:/usr/local/bin/
175             git clone ssh://gerrit.opnfv.org:29418/opnfvdocs docs_build/_opnfvdocs
176             GERRIT_COMMENT=gerrit_comment.txt ./docs_build/_opnfvdocs/scripts/docs-build.sh
177
178 - builder:
179     name: upload-under-review-docs-to-opnfv-artifacts
180     builders:
181         - shell: |
182             #!/bin/bash
183             set -o errexit
184             set -o pipefail
185             set -o xtrace
186             export PATH=$PATH:/usr/local/bin/
187
188             [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
189             [[ -d docs_output ]] || exit 0
190
191             echo
192             echo "###########################"
193             echo "UPLOADING DOCS UNDER REVIEW"
194             echo "###########################"
195             echo
196
197             gs_base="artifacts.opnfv.org/$PROJECT/review"
198             gs_path="$gs_base/$GERRIT_CHANGE_NUMBER"
199             local_path="upload/$GERRIT_CHANGE_NUMBER"
200
201             mkdir -p upload
202             mv docs_output "$local_path"
203             gsutil -m cp -r "$local_path" "gs://$gs_base"
204
205             gsutil -m setmeta \
206                 -h "Content-Type:text/html" \
207                 -h "Cache-Control:private, max-age=0, no-transform" \
208                 "gs://$gs_path"/**.html > /dev/null 2>&1
209
210             echo "Document link(s):" >> gerrit_comment.txt
211             find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
212                 sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt
213
214 - builder:
215     name: upload-generated-docs-to-opnfv-artifacts
216     builders:
217         - shell: |
218             #!/bin/bash
219             set -o errexit
220             set -o pipefail
221             set -o xtrace
222             export PATH=$PATH:/usr/local/bin/
223
224             [[ -d docs_output ]] || exit 0
225
226             echo
227             echo "########################"
228             echo "UPLOADING GENERATED DOCS"
229             echo "########################"
230             echo
231
232             echo "gs_path="$GS_URL/docs""
233             echo "local_path="upload/docs""
234
235             gs_path="$GS_URL/docs"
236             local_path="upload/docs"
237
238             mkdir -p upload
239             mv docs_output "$local_path"
240             ls "$local_path"
241
242             echo "gsutil -m cp -r "$local_path"/* "gs://$gs_path""
243             gsutil -m cp -r "$local_path"/* "gs://$gs_path"
244
245             gsutil -m setmeta \
246                 -h "Content-Type:text/html" \
247                 -h "Cache-Control:private, max-age=0, no-transform" \
248                 "gs://$gs_path"/**.html > /dev/null 2>&1
249
250             echo "Document link(s):" >> gerrit_comment.txt
251             find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
252                 sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt
253
254 - builder:
255     name: report-docs-build-result-to-gerrit
256     builders:
257         - shell: |
258             #!/bin/bash
259             set -o errexit
260             set -o pipefail
261             set -o xtrace
262             export PATH=$PATH:/usr/local/bin/
263             if [[ -e gerrit_comment.txt ]] ; then
264                 echo
265                 echo "posting review comment to gerrit..."
266                 echo
267                 cat gerrit_comment.txt
268                 echo
269                 ssh -p 29418 gerrit.opnfv.org \
270                     "gerrit review -p $GERRIT_PROJECT \
271                      -m '$(cat gerrit_comment.txt)' \
272                      $GERRIT_PATCHSET_REVISION \
273                      --notify NONE"
274             fi
275
276 - builder:
277     name: remove-old-docs-from-opnfv-artifacts
278     builders:
279         - shell: |
280             #!/bin/bash
281             set -o errexit
282             set -o pipefail
283             set -o xtrace
284             export PATH=$PATH:/usr/local/bin/
285
286             [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
287
288             gs_path="artifacts.opnfv.org/$PROJECT/review/$GERRIT_CHANGE_NUMBER"
289
290             if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
291                 echo
292                 echo "Deleting Out-of-dated Documents..."
293                 gsutil -m rm -r "gs://$gs_path"
294             fi
295             gs_path="artifacts.opnfv.org/review/$GERRIT_CHANGE_NUMBER"
296
297             if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
298                 echo
299                 echo "Deleting Out-of-dated Documents..."
300                 gsutil -m rm -r "gs://$gs_path"
301             fi
302
303 - builder:
304     name: build-and-upload-artifacts-json-api
305     builders:
306         - shell: |
307             #!/bin/bash
308             set -o errexit
309             set -o pipefail
310             export PATH=$PATH:/usr/local/bin/
311
312             virtualenv -p python2.7 $WORKSPACE/releng_artifacts
313             source $WORKSPACE/releng_artifacts/bin/activate
314
315             # install python packages
316             pip install google-api-python-client
317
318             # generate and upload index file
319             echo "Generating Artifacts API ..."
320             python $WORKSPACE/utils/opnfv-artifacts.py > index.json
321             gsutil cp index.json gs://artifacts.opnfv.org/index.json
322
323             deactivate
324
325 - builder:
326     name: lint-python-code
327     builders:
328         - shell: |
329             #!/bin/bash
330             set -o errexit
331             set -o pipefail
332             set -o xtrace
333             export PATH=$PATH:/usr/local/bin/
334
335             virtualenv -p python2.7 $WORKSPACE/releng_flake8
336             source $WORKSPACE/releng_flake8/bin/activate
337
338             # install python packages
339             pip install "flake8==2.6.2"
340
341             # generate and upload lint log
342             echo "Running flake8 code on $PROJECT ..."
343
344             # Get number of flake8 violations. If none, this will be an
345             # empty string: ""
346             FLAKE_COUNT="$(find . \
347                 -path './releng_flake8' -prune -o \
348                 -path './.tox' -prune -o \
349                 -type f -name "*.py" -print | \
350                 xargs flake8 --exit-zero -qq --count 2>&1)"
351
352             # Ensure we start with a clean environment
353             rm -f lint.log
354
355             if [ ! -z $FLAKE_COUNT ]; then
356               echo "Flake8 Violations: $FLAKE_COUNT" > lint.log
357               find . \
358                   -path './releng_flake8' -prune -o \
359                   -path './.tox' -prune -o \
360                   -type f -name "*.py" -print | \
361                   xargs flake8 --exit-zero --first >> violation.log
362               SHOWN=$(wc -l violation.log | cut -d' ' -f1)
363               echo -e "First $SHOWN shown\n---" >> lint.log
364               cat violation.log >> lint.log
365               sed -r -i '4,$s/^/ /g' lint.log
366               rm violation.log
367             fi
368
369             deactivate
370
371 - builder:
372     name: report-lint-result-to-gerrit
373     builders:
374         - shell: |
375             #!/bin/bash
376             set -o errexit
377             set -o pipefail
378             set -o xtrace
379             export PATH=$PATH:/usr/local/bin/
380
381             # If no violations were found, no lint log will exist.
382             if [[ -e lint.log ]] ; then
383                 echo -e "\nposting linting report to gerrit...\n"
384
385                 cat lint.log
386                 echo
387
388                 ssh -p 29418 gerrit.opnfv.org \
389                     "gerrit review -p $GERRIT_PROJECT \
390                      -m \"$(cat lint.log)\" \
391                      $GERRIT_PATCHSET_REVISION \
392                      --notify NONE"
393
394                 exit 1
395             fi
396
397 - builder:
398     name: upload-review-docs
399     builders:
400         - build-html-and-pdf-docs-output
401         - upload-under-review-docs-to-opnfv-artifacts
402         - report-docs-build-result-to-gerrit
403
404 - builder:
405     name: upload-merged-docs
406     builders:
407         - build-html-and-pdf-docs-output
408         - upload-generated-docs-to-opnfv-artifacts
409         - report-docs-build-result-to-gerrit
410         - remove-old-docs-from-opnfv-artifacts
411
412 - builder:
413     name: check-bash-syntax
414     builders:
415         - shell: "find . -name '*.sh' | xargs bash -n"
416
417 - builder:
418     name: lint-yaml-code
419     builders:
420         - shell: |
421             #!/bin/bash
422             set -o errexit
423             set -o pipefail
424             set -o xtrace
425             export PATH=$PATH:/usr/local/bin/
426
427             # install python packages
428             pip install "yamllint==1.6.0"
429
430             # generate and upload lint log
431             echo "Running yaml code on $PROJECT ..."
432
433             # Ensure we start with a clean environment
434             rm -f yaml-violation.log lint.log
435
436             # Get number of yaml violations. If none, this will be an
437             # empty string: ""
438             find . \
439                 -type f -name "*.yml" -print \
440                 -o -name "*.yaml" -print | \
441                 xargs yamllint > yaml-violation.log || true
442
443             if [ -s "yaml-violation.log" ]; then
444               SHOWN=$(cat yaml-violation.log| grep -v "^$" |wc -l)
445               echo -e "First $SHOWN shown\n---" > lint.log
446               cat yaml-violation.log >> lint.log
447               sed -r -i '4,$s/^/ /g' lint.log
448             fi
449
450 - builder:
451     name: clean-workspace-log
452     builders:
453         - shell: |
454             find $WORKSPACE -type f -name '*.log' | xargs rm -f
455
456 - publisher:
457     name: archive-artifacts
458     publishers:
459         - archive:
460             artifacts: '{artifacts}'
461             allow-empty: true
462             fingerprint: true
463             latest-only: true
464
465 - publisher:
466     name: publish-coverage
467     publishers:
468       - cobertura:
469           report-file: "coverage.xml"
470           only-stable: "true"
471           health-auto-update: "false"
472           stability-auto-update: "false"
473           zoom-coverage-chart: "true"
474           targets:
475             - files:
476                 healthy: 10
477                 unhealthy: 20
478                 failing: 30
479             - method:
480                 healthy: 50
481                 unhealthy: 40
482                 failing: 30
483