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