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