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