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