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