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