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