Fix bugs for new doc jobs
[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 - trigger:
78     name: 'daily-trigger-disabled'
79     triggers:
80         - timed: ''
81
82 - trigger:
83     name: 'weekly-trigger-disabled'
84     triggers:
85         - timed: ''
86
87 - trigger:
88     name: gerrit-trigger-patchset-created
89     triggers:
90         - gerrit:
91             server-name: 'gerrit.opnfv.org'
92             trigger-on:
93                 - patchset-created-event:
94                     exclude-drafts: 'false'
95                     exclude-trivial-rebase: 'false'
96                     exclude-no-code-change: 'false'
97                 - draft-published-event
98                 - comment-added-contains-event:
99                     comment-contains-value: 'recheck'
100             projects:
101               - project-compare-type: 'ANT'
102                 project-pattern: '{project}'
103                 branches:
104                   - branch-compare-type: 'ANT'
105                     branch-pattern: '**/{branch}'
106                 file-paths:
107                   - compare-type: 'ANT'
108                     pattern: '{files}'
109             skip-vote:
110                 successful: true
111                 failed: true
112                 unstable: true
113                 notbuilt: true
114
115 - trigger:
116     name: gerrit-trigger-change-merged
117     triggers:
118         - gerrit:
119             server-name: 'gerrit.opnfv.org'
120             trigger-on:
121                 - change-merged-event
122                 - comment-added-contains-event:
123                     comment-contains-value: 'remerge'
124             projects:
125               - project-compare-type: 'ANT'
126                 project-pattern: '{project}'
127                 branches:
128                   - branch-compare-type: 'ANT'
129                     branch-pattern: '**/{branch}'
130
131 - trigger:
132     name: 'experimental'
133     triggers:
134         - gerrit:
135             server-name: 'gerrit.opnfv.org'
136             trigger-on:
137                 - comment-added-contains-event:
138                     comment-contains-value: 'check-experimental'
139             projects:
140                 - project-compare-type: 'ANT'
141                   project-pattern: '{project}'
142                   branches:
143                       - branch-compare-type: 'ANT'
144                         branch-pattern: '**/{branch}'
145                   file-paths:
146                       - compare-type: 'ANT'
147                         pattern: 'tests/**'
148             skip-vote:
149                 successful: true
150                 failed: true
151                 unstable: true
152                 notbuilt: true
153
154 - wrapper:
155     name: ssh-agent-wrapper
156     wrappers:
157         - ssh-agent-credentials:
158             users:
159                 - 'd42411ac011ad6f3dd2e1fa34eaa5d87f910eb2e'
160
161 - builder:
162     name: build-html-and-pdf-docs-output
163     builders:
164         - shell: |
165             #!/bin/bash
166             set -o errexit
167             set -o xtrace
168             export PATH=$PATH:/usr/local/bin/
169             git clone ssh://gerrit.opnfv.org:29418/opnfvdocs docs_build/_opnfvdocs
170             GERRIT_COMMENT=gerrit_comment.txt ./docs_build/_opnfvdocs/scripts/docs-build.sh
171
172 - builder:
173     name: upload-under-review-docs-to-opnfv-artifacts
174     builders:
175         - shell: |
176             #!/bin/bash
177             set -o errexit
178             set -o pipefail
179             set -o xtrace
180             export PATH=$PATH:/usr/local/bin/
181
182             [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
183             [[ -d docs_output ]] || exit 0
184
185             echo
186             echo "###########################"
187             echo "UPLOADING DOCS UNDER REVIEW"
188             echo "###########################"
189             echo
190
191             gs_base="artifacts.opnfv.org/$PROJECT/review"
192             gs_path="$gs_base/$GERRIT_CHANGE_NUMBER"
193             local_path="upload/$GERRIT_CHANGE_NUMBER"
194
195             mkdir -p upload
196             mv docs_output "$local_path"
197             gsutil -m cp -r "$local_path" "gs://$gs_base"
198
199             gsutil -m setmeta \
200                 -h "Content-Type:text/html" \
201                 -h "Cache-Control:private, max-age=0, no-transform" \
202                 "gs://$gs_path"/**.html > /dev/null 2>&1
203
204             echo "Document link(s):" >> gerrit_comment.txt
205             find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
206                 sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt
207
208 - builder:
209     name: upload-generated-docs-to-opnfv-artifacts
210     builders:
211         - shell: |
212             #!/bin/bash
213             set -o errexit
214             set -o pipefail
215             set -o xtrace
216             export PATH=$PATH:/usr/local/bin/
217
218             [[ -d docs_output ]] || exit 0
219
220             echo
221             echo "########################"
222             echo "UPLOADING GENERATED DOCS"
223             echo "########################"
224             echo
225
226             echo "gs_path="$GS_URL/docs""
227             echo "local_path="upload/docs""
228
229             gs_path="$GS_URL/docs"
230             local_path="upload/docs"
231
232             mkdir -p upload
233             mv docs_output "$local_path"
234             ls "$local_path"
235
236             echo "gsutil -m cp -r "$local_path"/* "gs://$gs_path""
237             gsutil -m cp -r "$local_path"/* "gs://$gs_path"
238
239             gsutil -m setmeta \
240                 -h "Content-Type:text/html" \
241                 -h "Cache-Control:private, max-age=0, no-transform" \
242                 "gs://$gs_path"/**.html > /dev/null 2>&1
243
244             echo "Document link(s):" >> gerrit_comment.txt
245             find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
246                 sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt
247
248 - builder:
249     name: report-docs-build-result-to-gerrit
250     builders:
251         - shell: |
252             #!/bin/bash
253             set -o errexit
254             set -o pipefail
255             set -o xtrace
256             export PATH=$PATH:/usr/local/bin/
257             if [[ -e gerrit_comment.txt ]] ; then
258                 echo
259                 echo "posting review comment to gerrit..."
260                 echo
261                 cat gerrit_comment.txt
262                 echo
263                 ssh -p 29418 gerrit.opnfv.org \
264                     "gerrit review -p $GERRIT_PROJECT \
265                      -m '$(cat gerrit_comment.txt)' \
266                      $GERRIT_PATCHSET_REVISION \
267                      --notify NONE"
268             fi
269
270 - builder:
271     name: remove-old-docs-from-opnfv-artifacts
272     builders:
273         - shell: |
274             #!/bin/bash
275             set -o errexit
276             set -o pipefail
277             set -o xtrace
278             export PATH=$PATH:/usr/local/bin/
279
280             [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
281
282             gs_path="artifacts.opnfv.org/$PROJECT/review/$GERRIT_CHANGE_NUMBER"
283
284             if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
285                 echo
286                 echo "Deleting Out-of-dated Documents..."
287                 gsutil -m rm -r "gs://$gs_path"
288             fi
289             gs_path="artifacts.opnfv.org/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
297 - builder:
298     name: build-and-upload-artifacts-json-api
299     builders:
300         - shell: |
301             #!/bin/bash
302             set -o errexit
303             set -o pipefail
304             export PATH=$PATH:/usr/local/bin/
305
306             virtualenv -p python2.7 $WORKSPACE/releng_artifacts
307             source $WORKSPACE/releng_artifacts/bin/activate
308
309             # install python packages
310             pip install google-api-python-client
311
312             # generate and upload index file
313             echo "Generating Artifacts API ..."
314             python $WORKSPACE/utils/opnfv-artifacts.py > index.json
315             gsutil cp index.json gs://artifacts.opnfv.org/index.json
316
317             deactivate
318
319 - builder:
320     name: lint-python-code
321     builders:
322         - shell: |
323             #!/bin/bash
324             set -o errexit
325             set -o pipefail
326             set -o xtrace
327             export PATH=$PATH:/usr/local/bin/
328
329             virtualenv -p python2.7 $WORKSPACE/releng_flake8
330             source $WORKSPACE/releng_flake8/bin/activate
331
332             # install python packages
333             pip install "flake8==2.6.2"
334
335             # generate and upload lint log
336             echo "Running flake8 code on $PROJECT ..."
337
338             # Get number of flake8 violations. If none, this will be an
339             # empty string: ""
340             FLAKE_COUNT="$(find . \
341                 -path './releng_flake8' -prune -o \
342                 -path './.tox' -prune -o \
343                 -type f -name "*.py" -print | \
344                 xargs flake8 --exit-zero -qq --count 2>&1)"
345
346             # Ensure we start with a clean environment
347             rm -f lint.log
348
349             if [ ! -z $FLAKE_COUNT ]; then
350               echo "Flake8 Violations: $FLAKE_COUNT" > lint.log
351               find . \
352                   -path './releng_flake8' -prune -o \
353                   -path './.tox' -prune -o \
354                   -type f -name "*.py" -print | \
355                   xargs flake8 --exit-zero --first >> violation.log
356               SHOWN=$(wc -l violation.log | cut -d' ' -f1)
357               echo -e "First $SHOWN shown\n---" >> lint.log
358               cat violation.log >> lint.log
359               sed -r -i '4,$s/^/ /g' lint.log
360               rm violation.log
361             fi
362
363             deactivate
364
365 - builder:
366     name: report-lint-result-to-gerrit
367     builders:
368         - shell: |
369             #!/bin/bash
370             set -o errexit
371             set -o pipefail
372             set -o xtrace
373             export PATH=$PATH:/usr/local/bin/
374
375             # If no violations were found, no lint log will exist.
376             if [[ -e lint.log ]] ; then
377                 echo -e "\nposting linting report to gerrit...\n"
378
379                 cat lint.log
380                 echo
381
382                 ssh -p 29418 gerrit.opnfv.org \
383                     "gerrit review -p $GERRIT_PROJECT \
384                      -m \"$(cat lint.log)\" \
385                      $GERRIT_PATCHSET_REVISION \
386                      --notify NONE"
387
388                 exit 1
389             fi
390
391 - builder:
392     name: upload-review-docs
393     builders:
394         - build-html-and-pdf-docs-output
395         - upload-under-review-docs-to-opnfv-artifacts
396         - report-docs-build-result-to-gerrit
397
398 - builder:
399     name: upload-merged-docs
400     builders:
401         - build-html-and-pdf-docs-output
402         - upload-generated-docs-to-opnfv-artifacts
403         - report-docs-build-result-to-gerrit
404         - remove-old-docs-from-opnfv-artifacts
405
406 - builder:
407     name: check-bash-syntax
408     builders:
409         - shell: "find . -name '*.sh' | xargs bash -n"
410
411 - builder:
412     name: lint-yaml-code
413     builders:
414         - shell: |
415             #!/bin/bash
416             set -o errexit
417             set -o pipefail
418             set -o xtrace
419             export PATH=$PATH:/usr/local/bin/
420
421             # install python packages
422             pip install "yamllint==1.6.0"
423
424             # generate and upload lint log
425             echo "Running yaml code on $PROJECT ..."
426
427             # Ensure we start with a clean environment
428             rm -f yaml-violation.log lint.log
429
430             # Get number of yaml violations. If none, this will be an
431             # empty string: ""
432             find . \
433                 -type f -name "*.yml" -print \
434                 -o -name "*.yaml" -print | \
435                 xargs yamllint > yaml-violation.log || true
436
437             if [ -s "yaml-violation.log" ]; then
438               SHOWN=$(cat yaml-violation.log| grep -v "^$" |wc -l)
439               echo -e "First $SHOWN shown\n---" > lint.log
440               cat yaml-violation.log >> lint.log
441               sed -r -i '4,$s/^/ /g' lint.log
442             fi
443
444 - builder:
445     name: clean-workspace-log
446     builders:
447         - shell: |
448             find $WORKSPACE -type f -name '*.log' | xargs rm -f
449
450 - publisher:
451     name: archive-artifacts
452     publishers:
453         - archive:
454             artifacts: '{artifacts}'
455             allow-empty: true
456             fingerprint: true
457             latest-only: true