Merge "fix the bug of patch verify"
[releng.git] / jjb / global / releng-macros.yml
1 ---
2 # Releng macros
3 #
4 # NOTE: make sure macros are listed in execution ordered.
5 #
6 # 1. parameters/properties
7 # 2. scm
8 # 3. triggers
9 # 4. wrappers
10 # 5. prebuilders (maven only, configured like Builders)
11 # 6. builders (maven, freestyle, matrix, etc..)
12 # 7. postbuilders (maven only, configured like Builders)
13 # 8. publishers/reporters/notifications
14
15 - parameter:
16     name: project-parameter
17     parameters:
18       - string:
19           name: PROJECT
20           default: '{project}'
21           description: "JJB configured PROJECT parameter to identify an opnfv Gerrit project"
22       - string:
23           name: GS_BASE
24           default: artifacts.opnfv.org/$PROJECT
25           description: "URL to Google Storage."
26       - string:
27           name: GS_BASE_PROXY
28           default: build.opnfv.org/artifacts.opnfv.org/$PROJECT
29           description: "URL to Google Storage proxy"
30       - string:
31           name: BRANCH
32           default: '{branch}'
33           description: "JJB configured BRANCH parameter (e.g. master, stable/danube)"
34       - string:
35           name: GERRIT_BRANCH
36           default: '{branch}'
37           description: "JJB configured GERRIT_BRANCH parameter (deprecated)"
38
39 - property:
40     name: logrotate-default
41     properties:
42       - build-discarder:
43           days-to-keep: 60
44           num-to-keep: 200
45           artifact-days-to-keep: 60
46           artifact-num-to-keep: 200
47
48 - scm:
49     name: git-scm
50     scm:
51       - git: &git-scm-defaults
52           credentials-id: '$SSH_CREDENTIAL_ID'
53           url: '$GIT_BASE'
54           branches:
55             - 'origin/$BRANCH'
56           timeout: 15
57
58 - scm:
59     name: git-scm-gerrit
60     scm:
61       - git:
62           choosing-strategy: 'gerrit'
63           refspec: '$GERRIT_REFSPEC'
64           <<: *git-scm-defaults
65 - scm:
66     name: git-scm-with-submodules
67     scm:
68       - git:
69           credentials-id: '$SSH_CREDENTIAL_ID'
70           url: '$GIT_BASE'
71           refspec: ''
72           branches:
73             - 'refs/heads/{branch}'
74           skip-tag: true
75           wipe-workspace: true
76           submodule:
77             recursive: true
78             timeout: 20
79 - trigger:
80     name: 'daily-trigger-disabled'
81     triggers:
82       - timed: ''
83
84 - trigger:
85     name: 'weekly-trigger-disabled'
86     triggers:
87       - timed: ''
88
89 - trigger:
90     name: gerrit-trigger-patchset-created
91     triggers:
92       - gerrit:
93           server-name: 'gerrit.opnfv.org'
94           trigger-on:
95             - patchset-created-event:
96                 exclude-drafts: 'false'
97                 exclude-trivial-rebase: 'false'
98                 exclude-no-code-change: 'false'
99             - draft-published-event
100             - comment-added-contains-event:
101                 comment-contains-value: 'recheck'
102             - comment-added-contains-event:
103                 comment-contains-value: 'reverify'
104           projects:
105             - project-compare-type: 'ANT'
106               project-pattern: '{project}'
107               branches:
108                 - branch-compare-type: 'ANT'
109                   branch-pattern: '**/{branch}'
110               file-paths:
111                 - compare-type: 'ANT'
112                   pattern: '{files}'
113           skip-vote:
114             successful: false
115             failed: false
116             unstable: false
117             notbuilt: false
118
119 - trigger:
120     name: gerrit-trigger-change-merged
121     triggers:
122       - gerrit:
123           server-name: 'gerrit.opnfv.org'
124           trigger-on:
125             - change-merged-event
126             - comment-added-contains-event:
127                 comment-contains-value: 'remerge'
128           projects:
129             - project-compare-type: 'ANT'
130               project-pattern: '{project}'
131               branches:
132                 - branch-compare-type: 'ANT'
133                   branch-pattern: '**/{branch}'
134               file-paths:
135                 - compare-type: 'ANT'
136                   pattern: '{files}'
137
138 - trigger:
139     name: gerrit-trigger-tag-created
140     triggers:
141       - gerrit:
142           server-name: 'gerrit.opnfv.org'
143           trigger-on:
144             - ref-updated
145           projects:
146             - project-compare-type: 'ANT'
147               project-pattern: '{project}'
148               branches:
149                 - branch-compare-type: 'ANT'
150                   branch-pattern: 'refs/tags/**'
151
152 - trigger:
153     name: 'experimental'
154     triggers:
155       - gerrit:
156           server-name: 'gerrit.opnfv.org'
157           trigger-on:
158             - comment-added-contains-event:
159                 comment-contains-value: 'check-experimental'
160           projects:
161             - project-compare-type: 'ANT'
162               project-pattern: '{project}'
163               branches:
164                 - branch-compare-type: 'ANT'
165                   branch-pattern: '**/{branch}'
166               file-paths:
167                 - compare-type: 'ANT'
168                   pattern: '{files}'
169           skip-vote:
170             successful: true
171             failed: true
172             unstable: true
173             notbuilt: true
174
175 - wrapper:
176     name: ssh-agent-wrapper
177     wrappers:
178       - ssh-agent-credentials:
179           users:
180             - 'd42411ac011ad6f3dd2e1fa34eaa5d87f910eb2e'
181
182 - wrapper:
183     name: build-timeout
184     wrappers:
185       - timeout:
186           timeout: '{timeout}'
187           timeout-var: 'BUILD_TIMEOUT'
188           fail: true
189
190 - wrapper:
191     name: fix-workspace-permissions
192     wrappers:
193       - pre-scm-buildstep:
194           - shell: |
195              #!/bin/bash
196              sudo chown -R $USER:$USER $WORKSPACE || exit 1
197
198 - builder:
199     name: upload-under-review-docs-to-opnfv-artifacts
200     builders:
201       - shell: |
202           #!/bin/bash
203           set -o errexit
204           set -o pipefail
205           set -o xtrace
206           export PATH=$PATH:/usr/local/bin/
207
208           [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
209           [[ -d docs/_build/ ]] || exit 0
210
211           echo
212           echo "###########################"
213           echo "UPLOADING DOCS UNDER REVIEW"
214           echo "###########################"
215           echo
216
217           gs_base="artifacts.opnfv.org/$PROJECT/review"
218           gs_path="$gs_base/$GERRIT_CHANGE_NUMBER"
219           local_path="upload/$GERRIT_CHANGE_NUMBER"
220
221           mkdir -p upload
222           mv docs/_build/html/ "$local_path"
223           gsutil -m cp -r "$local_path" "gs://$gs_base"
224
225           gsutil -m setmeta \
226               -h "Content-Type:text/html" \
227               -h "Cache-Control:private, max-age=0, no-transform" \
228               "gs://$gs_path"/**.html > /dev/null 2>&1
229
230           echo "Document link(s):" >> gerrit_comment.txt
231           find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
232               sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt
233
234 # To take advantage of this macro, have your build write
235 # out the file 'gerrit_comment.txt' with information to post
236 # back to gerrit and include this macro in the list of builders.
237 - builder:
238     name: report-build-result-to-gerrit
239     builders:
240       - shell: |
241           #!/bin/bash
242           set -o errexit
243           set -o pipefail
244           set -o xtrace
245           export PATH=$PATH:/usr/local/bin/
246           if [[ -e gerrit_comment.txt ]] ; then
247               echo
248               echo "posting review comment to gerrit..."
249               echo
250               cat gerrit_comment.txt
251               echo
252               ssh -p 29418 gerrit.opnfv.org \
253                   "gerrit review -p $GERRIT_PROJECT \
254                    -m '$(cat gerrit_comment.txt)' \
255                    $GERRIT_PATCHSET_REVISION \
256                    --notify NONE"
257           fi
258
259 - builder:
260     name: remove-old-docs-from-opnfv-artifacts
261     builders:
262       - shell: |
263           #!/bin/bash
264           set -o errexit
265           set -o pipefail
266           set -o xtrace
267           export PATH=$PATH:/usr/local/bin/
268
269           [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
270
271           gs_path="artifacts.opnfv.org/$PROJECT/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           gs_path="artifacts.opnfv.org/review/$GERRIT_CHANGE_NUMBER"
279
280           if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
281               echo
282               echo "Deleting Out-of-dated Documents..."
283               gsutil -m rm -r "gs://$gs_path"
284           fi
285
286 - builder:
287     name: lint-python-code
288     builders:
289       - shell: |
290           #!/bin/bash
291           set -o errexit
292           set -o pipefail
293           set -o xtrace
294           export PATH=$PATH:/usr/local/bin/
295
296           virtualenv -p python2.7 $WORKSPACE/releng_flake8
297           source $WORKSPACE/releng_flake8/bin/activate
298
299           # install python packages
300           pip install "flake8==2.6.2"
301
302           # generate and upload lint log
303           echo "Running flake8 code on $PROJECT ..."
304
305           # Get number of flake8 violations. If none, this will be an
306           # empty string: ""
307           FLAKE_COUNT="$(find . \
308               -path './releng_flake8' -prune -o \
309               -path './.tox' -prune -o \
310               -type f -name "*.py" -print | \
311               xargs flake8 --exit-zero -qq --count 2>&1)"
312
313           # Ensure we start with a clean environment
314           rm -f lint.log
315
316           if [ ! -z $FLAKE_COUNT ]; then
317             echo "Flake8 Violations: $FLAKE_COUNT" > lint.log
318             find . \
319                 -path './releng_flake8' -prune -o \
320                 -path './.tox' -prune -o \
321                 -type f -name "*.py" -print | \
322                 xargs flake8 --exit-zero --first >> violation.log
323             SHOWN=$(wc -l violation.log | cut -d' ' -f1)
324             echo -e "First $SHOWN shown\n---" >> lint.log
325             cat violation.log >> lint.log
326             sed -r -i '4,$s/^/ /g' lint.log
327             rm violation.log
328           fi
329
330           deactivate
331
332 - builder:
333     name: report-lint-result-to-gerrit
334     builders:
335       - shell: |
336           #!/bin/bash
337           set -o errexit
338           set -o pipefail
339           set -o xtrace
340           export PATH=$PATH:/usr/local/bin/
341
342           # If no violations were found, no lint log will exist.
343           if [[ -e lint.log ]] ; then
344               echo -e "\nposting linting report to gerrit...\n"
345
346               cat lint.log
347               echo
348
349               ssh -p 29418 gerrit.opnfv.org \
350                   "gerrit review -p $GERRIT_PROJECT \
351                    -m \"$(cat lint.log)\" \
352                    $GERRIT_PATCHSET_REVISION \
353                    --notify NONE"
354
355               exit 1
356           fi
357
358 - builder:
359     name: upload-review-docs
360     builders:
361       - upload-under-review-docs-to-opnfv-artifacts
362       - report-build-result-to-gerrit
363
364 - builder:
365     name: check-bash-syntax
366     builders:
367       - shell: "find . -name '*.sh' | xargs bash -n"
368
369 - builder:
370     name: lint-yaml-code
371     builders:
372       - shell: |
373           #!/bin/bash
374           set -o errexit
375           set -o pipefail
376           set -o xtrace
377           export PATH=$PATH:/usr/local/bin/
378
379           # install python packages
380           sudo pip install "yamllint==1.8.2"
381
382           # generate and upload lint log
383           echo "Running yaml code on $PROJECT ..."
384
385           # Get list of yaml files
386           YAML_FILES=$(git --no-pager diff --diff-filter=MCRAT --name-only HEAD^1 | egrep "ya?ml$") || true
387
388           #If YAML_FILES is none exit with 0
389           if [ -z "$YAML_FILES" ]; then
390               exit 0
391           fi
392
393           # Ensure we start with a clean environment
394           rm -f yaml-violation.log lint.log
395
396           # Yamllint files only in patchset
397           for yamlfile in $YAML_FILES; do
398             yamllint $yamlfile >> yaml-violation.log || true
399           done
400
401           if [ -s "yaml-violation.log" ]; then
402             SHOWN=$(grep -c -v "^$" yaml-violation.log)
403             echo -e "First $SHOWN shown\n---" > lint.log
404             cat yaml-violation.log >> lint.log
405             sed -r -i '4,$s/^/ /g' lint.log
406           fi
407
408 - builder:
409     name: clean-workspace
410     builders:
411       - shell: |
412           #!/bin/bash
413           set -o errexit
414           set -o nounset
415           set -o pipefail
416           sudo /bin/rm -rf "$WORKSPACE"
417
418 - builder:
419     name: clean-workspace-log
420     builders:
421       - shell: |
422           find $WORKSPACE -type f -name '*.log' | xargs rm -f
423
424 - publisher:
425     name: archive-artifacts
426     publishers:
427       - archive:
428           artifacts: '{artifacts}'
429           allow-empty: true
430           fingerprint: true
431           latest-only: true
432
433 - publisher:
434     name: publish-coverage
435     publishers:
436       - cobertura:
437           report-file: "coverage.xml"
438           only-stable: "true"
439           health-auto-update: "false"
440           stability-auto-update: "false"
441           zoom-coverage-chart: "true"
442           targets:
443             - files:
444                 healthy: 10
445                 unhealthy: 20
446                 failing: 30
447             - method:
448                 healthy: 50
449                 unhealthy: 40
450                 failing: 30
451
452 # The majority of the email-ext plugin options are set to the default
453 # for this macro so they can be managed through Jenkins' global
454 # settings.
455 - publisher:
456     name: email-jenkins-admins-on-failure
457     publishers:
458       - email-ext:
459           content-type: text
460           attach-build-log: true
461           compress-log: true
462           always: false
463           failure: true
464           send-to:
465             - recipients