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