Remove Security Jobs
[releng.git] / jjb / global / releng-macros.yaml
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       - string:
39           name: GERRIT_REFSPEC
40           default: 'refs/heads/{branch}'
41           description: "Default refspec needed for manually triggering."
42
43 ##
44 # Reporting Deployment Results
45 #
46 # To report deployment results to
47 # http://testresults.opnfv.org/test/#/deployresults, add the following
48 # parameters, builders, and publishers to a deployment job:
49 #
50 #   parameters:
51 #    - testapi-parameter
52 #
53 #   builders:
54 #    - track-begin-timestamp
55 #
56 #   publishers:
57 #    - report-provision-result
58 #
59 # Note: The following string parameter must also exist, as they are used
60 #       when reporting the provision result:
61 #
62 #  * INSTALLER
63 #  * INSTALLER_VERSION
64 #  * DEPLOY_SCENARIO
65 #
66 # most installers include these but you should verify first before
67 # adding the publisher, otherwise the deployment build may be marked
68 # unstable.
69 #
70 ##
71 - parameter:
72     name: testapi-parameter
73     parameters:
74       - string:
75           name: TESTAPI_URL
76           default: 'http://testresults.opnfv.org/test/api/v1'
77           description: "Default TestAPI URL, currently using v1"
78       - string:
79           name: INSTALLER_VERSION
80           default: 'master'
81           description: "Installer release version"
82       - string:
83           name: UPSTREAM_JOB_NAME
84           default: ''
85           description: "Parent job name in Jenkins"
86       - string:
87           name: UPSTREAM_BUILD_ID
88           default: ''
89           description: "Parent job build_id in Jenkins"
90
91 - property:
92     name: logrotate-default
93     properties:
94       - build-discarder:
95           days-to-keep: 60
96           num-to-keep: 200
97           artifact-days-to-keep: 60
98           artifact-num-to-keep: 200
99
100 - scm:
101     name: git-scm
102     scm:
103       - git: &git-scm-defaults
104           credentials-id: 'd42411ac011ad6f3dd2e1fa34eaa5d87f910eb2e'
105           url: '$GIT_BASE'
106           branches:
107             - 'origin/$BRANCH'
108           timeout: 15
109           per-build-tag: false
110           skip-tag: true
111           shallow-clone: false
112           use-author: false
113           ignore-notify: false
114           wipe-workspace: true
115           prune: false
116
117 - scm:
118     name: git-scm-gerrit
119     scm:
120       - git:
121           choosing-strategy: 'gerrit'
122           refspec: '$GERRIT_REFSPEC'
123           <<: *git-scm-defaults
124
125 - scm:
126     name: git-scm-gerrit-with-submodules
127     scm:
128       - git:
129           choosing-strategy: 'gerrit'
130           refspec: '$GERRIT_REFSPEC'
131           submodule:
132             recursive: true
133             timeout: 20
134           <<: *git-scm-defaults
135 - scm:
136     name: git-scm-with-submodules
137     scm:
138       - git:
139           credentials-id: 'd42411ac011ad6f3dd2e1fa34eaa5d87f910eb2e'
140           url: '$GIT_BASE'
141           refspec: ''
142           branches:
143             - 'refs/heads/{branch}'
144           per-build-tag: false
145           skip-tag: true
146           wipe-workspace: true
147           submodule:
148             recursive: true
149             timeout: 20
150
151 - scm:
152     name: git-scm-openstack
153     scm:
154       - git: &git-scm-openstack-defaults
155           per-build-tag: false
156           skip-tag: true
157           url: '$GIT_BASE'
158           branches:
159             - 'origin/$BRANCH'
160           timeout: 15
161
162 - trigger:
163     name: 'daily-trigger-disabled'
164     triggers:
165       - timed: ''
166
167 - trigger:
168     name: 'weekly-trigger-disabled'
169     triggers:
170       - timed: ''
171
172 - trigger:
173     name: gerrit-trigger-patchset-created
174     triggers:
175       - gerrit:
176           server-name: 'gerrit.opnfv.org'
177           trigger-on:
178             - patchset-created-event:
179                 exclude-drafts: 'false'
180                 exclude-trivial-rebase: 'false'
181                 exclude-no-code-change: 'false'
182             - draft-published-event
183             - comment-added-contains-event:
184                 comment-contains-value: 'recheck'
185             - comment-added-contains-event:
186                 comment-contains-value: 'reverify'
187           projects:
188             - project-compare-type: 'ANT'
189               project-pattern: '{project}'
190               branches:
191                 - branch-compare-type: 'ANT'
192                   branch-pattern: '**/{branch}'
193               file-paths:
194                 - compare-type: 'ANT'
195                   pattern: '{files}'
196           skip-vote:
197             successful: false
198             failed: false
199             unstable: false
200             notbuilt: false
201
202 - trigger:
203     name: gerrit-trigger-patchset-approved
204     triggers:
205       - gerrit:
206           server-name: 'gerrit.opnfv.org'
207           trigger-on:
208             - comment-added-event:
209                 approval-category: 'CRVW'
210                 approval-value: 2
211             - comment-added-contains-event:
212                 comment-contains-value: 'gate'
213           projects:
214             - project-compare-type: 'ANT'
215               project-pattern: '{project}'
216               branches:
217                 - branch-compare-type: 'ANT'
218                   branch-pattern: '**/{branch}'
219               file-paths:
220                 - compare-type: 'ANT'
221                   pattern: '{files}'
222           skip-vote:
223             successful: false
224             failed: false
225             unstable: false
226             notbuilt: false
227
228 - trigger:
229     name: gerrit-trigger-change-merged
230     triggers:
231       - gerrit:
232           server-name: 'gerrit.opnfv.org'
233           trigger-on:
234             - change-merged-event
235             - comment-added-contains-event:
236                 comment-contains-value: 'remerge'
237           projects:
238             - project-compare-type: 'ANT'
239               project-pattern: '{project}'
240               branches:
241                 - branch-compare-type: 'ANT'
242                   branch-pattern: '**/{branch}'
243               file-paths:
244                 - compare-type: 'ANT'
245                   pattern: '{files}'
246
247 - trigger:
248     name: gerrit-trigger-tag-created
249     triggers:
250       - gerrit:
251           server-name: 'gerrit.opnfv.org'
252           trigger-on:
253             - ref-updated-event
254           projects:
255             - project-compare-type: 'ANT'
256               project-pattern: '{project}'
257               branches:
258                 - branch-compare-type: 'ANT'
259                   branch-pattern: 'refs/tags/**'
260
261 - trigger:
262     name: 'experimental'
263     triggers:
264       - gerrit:
265           server-name: 'gerrit.opnfv.org'
266           trigger-on:
267             - comment-added-contains-event:
268                 comment-contains-value: 'check-experimental'
269           projects:
270             - project-compare-type: 'ANT'
271               project-pattern: '{project}'
272               branches:
273                 - branch-compare-type: 'ANT'
274                   branch-pattern: '**/{branch}'
275               file-paths:
276                 - compare-type: 'ANT'
277                   pattern: '{files}'
278           skip-vote:
279             successful: true
280             failed: true
281             unstable: true
282             notbuilt: true
283
284 - wrapper:
285     name: ssh-agent-wrapper
286     wrappers:
287       - ssh-agent-credentials:
288           users:
289             - 'd42411ac011ad6f3dd2e1fa34eaa5d87f910eb2e'
290
291 - wrapper:
292     name: build-timeout
293     wrappers:
294       - timeout:
295           timeout: '{timeout}'
296           timeout-var: 'BUILD_TIMEOUT'
297           fail: true
298
299 - wrapper:
300     name: fix-workspace-permissions
301     wrappers:
302       - pre-scm-buildstep:
303           - shell: |
304              #!/bin/bash
305              sudo chown -R $USER:$USER $WORKSPACE || exit 1
306
307 - builder:
308     name: upload-under-review-docs-to-opnfv-artifacts
309     builders:
310       - shell: |
311           #!/bin/bash
312           set -o errexit
313           set -o pipefail
314           set -o xtrace
315           export PATH=$PATH:/usr/local/bin/
316
317           [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
318           [[ -d docs/_build/ ]] || exit 0
319
320           echo
321           echo "###########################"
322           echo "UPLOADING DOCS UNDER REVIEW"
323           echo "###########################"
324           echo
325
326           gs_base="artifacts.opnfv.org/$PROJECT/review"
327           gs_path="$gs_base/$GERRIT_CHANGE_NUMBER"
328           local_path="upload/$GERRIT_CHANGE_NUMBER"
329
330           mkdir -p upload
331           mv docs/_build/html/ "$local_path"
332           gsutil -m cp -r "$local_path" "gs://$gs_base"
333
334           gsutil -m setmeta \
335               -h "Content-Type:text/html" \
336               -h "Cache-Control:private, max-age=0, no-transform" \
337               "gs://$gs_path"/**.html > /dev/null 2>&1
338
339           echo "Document link(s):" >> gerrit_comment.txt
340           find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
341               sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt
342
343 # To take advantage of this macro, have your build write
344 # out the file 'gerrit_comment.txt' with information to post
345 # back to gerrit and include this macro in the list of builders.
346 - builder:
347     name: report-build-result-to-gerrit
348     builders:
349       - shell: |
350           #!/bin/bash
351           set -o errexit
352           set -o pipefail
353           set -o xtrace
354           export PATH=$PATH:/usr/local/bin/
355           if [[ -e gerrit_comment.txt ]] ; then
356               echo
357               echo "posting review comment to gerrit..."
358               echo
359               cat gerrit_comment.txt
360               echo
361               ssh -p 29418 gerrit.opnfv.org \
362                   "gerrit review -p $GERRIT_PROJECT \
363                    -m '$(cat gerrit_comment.txt)' \
364                    $GERRIT_PATCHSET_REVISION \
365                    --notify NONE"
366           fi
367
368 - builder:
369     name: remove-old-docs-from-opnfv-artifacts
370     builders:
371       - shell: |
372           #!/bin/bash
373           set -o errexit
374           set -o pipefail
375           set -o xtrace
376           export PATH=$PATH:/usr/local/bin/
377
378           [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
379
380           gs_path="artifacts.opnfv.org/$PROJECT/review/$GERRIT_CHANGE_NUMBER"
381
382           if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
383               echo
384               echo "Deleting Out-of-dated Documents..."
385               gsutil -m rm -r "gs://$gs_path"
386           fi
387           gs_path="artifacts.opnfv.org/review/$GERRIT_CHANGE_NUMBER"
388
389           if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
390               echo
391               echo "Deleting Out-of-dated Documents..."
392               gsutil -m rm -r "gs://$gs_path"
393           fi
394
395 - builder:
396     name: upload-review-docs
397     builders:
398       - upload-under-review-docs-to-opnfv-artifacts
399       - report-build-result-to-gerrit
400
401 - builder:
402     name: lint-init
403     builders:
404       - shell: |
405           #!/bin/bash
406           # Ensure we start with a clean environment
407           rm -f bash-violation.log python-violation.log yaml-violation.log violation.log
408           git --no-pager diff --diff-filter=MCRAT --name-only HEAD^1 > modified_files
409
410 - builder:
411     name: lint-report
412     builders:
413       - shell: |
414           #!/bin/bash
415           if [[ -s violation.log ]]; then
416               cat violation.log
417               echo "Reporting lint result...."
418               set -x
419               msg="Found syntax error and/or coding style violation(s) in the files modified by your patchset."
420               sed -i -e "1s#^#${msg}\n\n#" violation.log
421               cmd="gerrit review -p $GERRIT_PROJECT -m \"$(cat violation.log)\" $GERRIT_PATCHSET_REVISION --notify NONE"
422               ssh -p 29418 gerrit.opnfv.org "$cmd"
423
424               # Make sure the caller job failed
425               exit 1
426           fi
427
428 - builder:
429     name: lint-bash-code
430     builders:
431       - shell: |
432           #!/bin/bash
433           echo "Checking bash code..."
434           for f in $(egrep '\.sh$' modified_files)
435           do
436               bash -n "$f" 2>> bash-violation.log
437           done
438           if [[ -s bash-violation.log ]]; then
439               echo -e "Bash syntax error(s)\n---" >> violation.log
440               sed -e 's/^/ /g' bash-violation.log >> violation.log
441           fi
442
443 - builder:
444     name: lint-python-code
445     builders:
446       - shell: |
447           #!/bin/bash
448           # Install python package
449           sudo -H pip install "flake8==2.6.2"
450
451           echo "Checking python code..."
452           for f in $(egrep '\.py$' modified_files)
453           do
454               flake8 "$f" >> python-violation.log
455           done
456           if [[ -s python-violation.log ]]; then
457               echo -e "Python violation(s)\n---" >> violation.log
458               sed -e 's/^/ /g' python-violation.log >> violation.log
459           fi
460
461 - builder:
462     name: lint-yaml-code
463     builders:
464       - shell: |
465           #!/bin/bash
466           # sudo Install python packages
467           sudo -H pip install "yamllint==1.8.2"
468
469           echo "Checking yaml file..."
470           for f in $(egrep '\.ya?ml$' modified_files)
471           do
472               yamllint "$f" >> yaml-violation.log
473           done
474           if [[ -s yaml-violation.log ]]; then
475               echo -e "YAML violation(s)\n---" >> violation.log
476               sed -e 's/^/ /g' yaml-violation.log >> violation.log
477           fi
478
479 - builder:
480     name: lint-all-code
481     builders:
482       - lint-init
483       - lint-bash-code
484       - lint-python-code
485       - lint-yaml-code
486       - lint-report
487
488 - builder:
489     name: clean-workspace
490     builders:
491       - shell: |
492           #!/bin/bash
493           set -o errexit
494           set -o nounset
495           set -o pipefail
496           sudo /bin/rm -rf "$WORKSPACE"
497
498 - builder:
499     name: clean-workspace-log
500     builders:
501       - shell: |
502           find $WORKSPACE -type f -name '*.log' | xargs rm -f
503
504 - builder:
505     name: track-begin-timestamp
506     builders:
507       - shell: |
508           echo "export TIMESTAMP_START="\'`date '+%Y-%m-%d %H:%M:%S.%3N'`\' > $WORKSPACE/installer_track.sh
509
510 - publisher:
511     name: archive-artifacts
512     publishers:
513       - archive:
514           artifacts: '{artifacts}'
515           allow-empty: true
516           fingerprint: true
517           latest-only: true
518
519 - publisher:
520     name: publish-coverage
521     publishers:
522       - cobertura:
523           report-file: "coverage.xml"
524           only-stable: "true"
525           health-auto-update: "false"
526           stability-auto-update: "false"
527           zoom-coverage-chart: "true"
528           targets:
529             - files:
530                 healthy: 10
531                 unhealthy: 20
532                 failing: 30
533             - method:
534                 healthy: 50
535                 unhealthy: 40
536                 failing: 30
537
538 # The majority of the email-ext plugin options are set to the default
539 # for this macro so they can be managed through Jenkins' global
540 # settings.
541 - publisher:
542     name: email-jenkins-admins-on-failure
543     publishers:
544       - email-ext:
545           content-type: text
546           attach-build-log: true
547           compress-log: true
548           always: false
549           failure: true
550           send-to:
551             - recipients
552
553 - publisher:
554     name: 'report-provision-result'
555     publishers:
556       - postbuildscript:
557           builders:
558             - role: BOTH
559               build-on:
560                 - SUCCESS
561               build-steps:
562                 - shell: |
563                     echo "export PROVISION_RESULT=PASS" >> $WORKSPACE/installer_track.sh
564                     echo "export INSTALLER=$INSTALLER_TYPE" >> $WORKSPACE/installer_track.sh
565                     echo "export TIMESTAMP_END="\'`date '+%Y-%m-%d %H:%M:%S.%3N'`\' >> $WORKSPACE/installer_track.sh
566                 - shell:
567                     !include-raw: installer-report.sh
568           mark-unstable-if-failed: true
569       - postbuildscript:
570           builders:
571             - role: BOTH
572               build-on:
573                 - ABORTED
574                 - FAILURE
575                 - NOT_BUILT
576                 - UNSTABLE
577               build-steps:
578                 - shell: |
579                     echo "export PROVISION_RESULT=FAIL" >> $WORKSPACE/installer_track.sh
580                     echo "export INSTALLER=$INSTALLER_TYPE" >> $WORKSPACE/installer_track.sh
581                     echo "export TIMESTAMP_END="\'`date '+%Y-%m-%d %H:%M:%S.%3N'`\' >> $WORKSPACE/installer_track.sh
582                 - shell:
583                     !include-raw: installer-report.sh
584           mark-unstable-if-failed: true