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