summaryrefslogtreecommitdiffstats
path: root/jjb/global/releng-macros.yaml
blob: b82fbea95bad46617082e8e5e61de67b2b47e06e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
---
# Releng macros
#
# NOTE: make sure macros are listed in execution ordered.
#
# 1. parameters/properties
# 2. scm
# 3. triggers
# 4. wrappers
# 5. prebuilders (maven only, configured like Builders)
# 6. builders (maven, freestyle, matrix, etc..)
# 7. postbuilders (maven only, configured like Builders)
# 8. publishers/reporters/notifications

- parameter:
    name: project-parameter
    parameters:
      - string:
          name: PROJECT
          default: '{project}'
          description: "JJB configured PROJECT parameter to identify an opnfv Gerrit project"
      - string:
          name: GS_BASE
          default: artifacts.opnfv.org/$PROJECT
          description: "URL to Google Storage."
      - string:
          name: GS_BASE_PROXY
          default: build.opnfv.org/artifacts.opnfv.org/$PROJECT
          description: "URL to Google Storage proxy"
      - string:
          name: BRANCH
          default: '{branch}'
          description: "JJB configured BRANCH parameter (e.g. master, stable/danube)"
      - string:
          name: GERRIT_BRANCH
          default: '{branch}'
          description: "JJB configured GERRIT_BRANCH parameter (deprecated)"
      - string:
          name: GERRIT_REFSPEC
          default: 'refs/heads/{branch}'
          description: "Default refspec needed for manually triggering."

##
# Reporting Deployment Results
#
# To report deployment results to
# http://testresults.opnfv.org/test/#/deployresults, add the following
# parameters, builders, and publishers to a deployment job:
#
#   parameters:
#    - testapi-parameter
#
#   builders:
#    - track-begin-timestamp
#
#   publishers:
#    - report-provision-result
#
# Note: The following string parameter must also exist, as they are used
#       when reporting the provision result:
#
#  * INSTALLER
#  * INSTALLER_VERSION
#  * DEPLOY_SCENARIO
#
# most installers include these but you should verify first before
# adding the publisher, otherwise the deployment build may be marked
# unstable.
#
##
- parameter:
    name: testapi-parameter
    parameters:
      - string:
          name: TESTAPI_URL
          default: 'http://testresults.opnfv.org/test/api/v1'
          description: "Default TestAPI URL, currently using v1"
      - string:
          name: INSTALLER_VERSION
          default: 'master'
          description: "Installer release version"
      - string:
          name: UPSTREAM_JOB_NAME
          default: ''
          description: "Parent job name in Jenkins"
      - string:
          name: UPSTREAM_BUILD_ID
          default: ''
          description: "Parent job build_id in Jenkins"

- property:
    name: logrotate-default
    properties:
      - build-discarder:
          days-to-keep: 60
          num-to-keep: 200
          artifact-days-to-keep: 60
          artifact-num-to-keep: 200

- scm:
    name: git-scm
    scm:
      - git: &git-scm-defaults
          credentials-id: 'd42411ac011ad6f3dd2e1fa34eaa5d87f910eb2e'
          url: '$GIT_BASE'
          branches:
            - 'origin/$BRANCH'
          timeout: 15
          per-build-tag: false
          skip-tag: true
          shallow-clone: false
          use-author: false
          ignore-notify: false
          wipe-workspace: true
          prune: false

- scm:
    name: git-scm-gerrit
    scm:
      - git:
          choosing-strategy: 'gerrit'
          refspec: '$GERRIT_REFSPEC'
          <<: *git-scm-defaults

- scm:
    name: git-scm-gerrit-with-submodules
    scm:
      - git:
          choosing-strategy: 'gerrit'
          refspec: '$GERRIT_REFSPEC'
          submodule:
            recursive: true
            timeout: 20
          <<: *git-scm-defaults
- scm:
    name: git-scm-with-submodules
    scm:
      - git:
          credentials-id: 'd42411ac011ad6f3dd2e1fa34eaa5d87f910eb2e'
          url: '$GIT_BASE'
          refspec: ''
          branches:
            - 'refs/heads/{branch}'
          per-build-tag: false
          skip-tag: true
          wipe-workspace: true
          submodule:
            recursive: true
            timeout: 20

- scm:
    name: git-scm-openstack
    scm:
      - git: &git-scm-openstack-defaults
          per-build-tag: false
          skip-tag: true
          url: '$GIT_BASE'
          branches:
            - 'origin/$BRANCH'
          timeout: 15

- trigger:
    name: 'daily-trigger-disabled'
    triggers:
      - timed: ''

- trigger:
    name: 'weekly-trigger-disabled'
    triggers:
      - timed: ''

- trigger:
    name: gerrit-trigger-patchset-created
    triggers:
      - gerrit:
          server-name: 'gerrit.opnfv.org'
          trigger-on:
            - patchset-created-event:
                exclude-drafts: 'false'
                exclude-trivial-rebase: 'false'
                exclude-no-code-change: 'false'
            - draft-published-event
            - comment-added-contains-event:
                comment-contains-value: 'recheck'
            - comment-added-contains-event:
                comment-contains-value: 'reverify'
          projects:
            - project-compare-type: 'ANT'
              project-pattern: '{project}'
              branches:
                - branch-compare-type: 'ANT'
                  branch-pattern: '**/{branch}'
              file-paths:
                - compare-type: 'ANT'
                  pattern: '{files}'
          skip-vote:
            successful: false
            failed: false
            unstable: false
            notbuilt: false

- trigger:
    name: gerrit-trigger-patchset-approved
    triggers:
      - gerrit:
          server-name: 'gerrit.opnfv.org'
          trigger-on:
            - comment-added-event:
                approval-category: 'CRVW'
                approval-value: 2
            - comment-added-contains-event:
                comment-contains-value: 'gate'
          projects:
            - project-compare-type: 'ANT'
              project-pattern: '{project}'
              branches:
                - branch-compare-type: 'ANT'
                  branch-pattern: '**/{branch}'
              file-paths:
                - compare-type: 'ANT'
                  pattern: '{files}'
          skip-vote:
            successful: false
            failed: false
            unstable: false
            notbuilt: false

- trigger:
    name: gerrit-trigger-change-merged
    triggers:
      - gerrit:
          server-name: 'gerrit.opnfv.org'
          trigger-on:
            - change-merged-event
            - comment-added-contains-event:
                comment-contains-value: 'remerge'
          projects:
            - project-compare-type: 'ANT'
              project-pattern: '{project}'
              branches:
                - branch-compare-type: 'ANT'
                  branch-pattern: '**/{branch}'
              file-paths:
                - compare-type: 'ANT'
                  pattern: '{files}'

- trigger:
    name: gerrit-trigger-tag-created
    triggers:
      - gerrit:
          server-name: 'gerrit.opnfv.org'
          trigger-on:
            - ref-updated-event
          projects:
            - project-compare-type: 'ANT'
              project-pattern: '{project}'
              branches:
                - branch-compare-type: 'ANT'
                  branch-pattern: 'refs/tags/**'

- trigger:
    name: 'experimental'
    triggers:
      - gerrit:
          server-name: 'gerrit.opnfv.org'
          trigger-on:
            - comment-added-contains-event:
                comment-contains-value: 'check-experimental'
          projects:
            - project-compare-type: 'ANT'
              project-pattern: '{project}'
              branches:
                - branch-compare-type: 'ANT'
                  branch-pattern: '**/{branch}'
              file-paths:
                - compare-type: 'ANT'
                  pattern: '{files}'
          skip-vote:
            successful: true
            failed: true
            unstable: true
            notbuilt: true

- wrapper:
    name: ssh-agent-wrapper
    wrappers:
      - ssh-agent-credentials:
          users:
            - 'd42411ac011ad6f3dd2e1fa34eaa5d87f910eb2e'

- wrapper:
    name: build-timeout
    wrappers:
      - timeout:
          timeout: '{timeout}'
          timeout-var: 'BUILD_TIMEOUT'
          fail: true

- wrapper:
    name: fix-workspace-permissions
    wrappers:
      - pre-scm-buildstep:
          - shell: |
             #!/bin/bash
             sudo chown -R $USER:$USER $WORKSPACE || exit 1

- builder:
    name: upload-under-review-docs-to-opnfv-artifacts
    builders:
      - shell: |
          #!/bin/bash
          set -o errexit
          set -o pipefail
          set -o xtrace
          export PATH=$PATH:/usr/local/bin/

          [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
          [[ -d docs/_build/ ]] || exit 0

          echo
          echo "###########################"
          echo "UPLOADING DOCS UNDER REVIEW"
          echo "###########################"
          echo

          gs_base="artifacts.opnfv.org/$PROJECT/review"
          gs_path="$gs_base/$GERRIT_CHANGE_NUMBER"
          local_path="upload/$GERRIT_CHANGE_NUMBER"

          mkdir -p upload
          mv docs/_build/html/ "$local_path"
          gsutil -m cp -r "$local_path" "gs://$gs_base"

          gsutil -m setmeta \
              -h "Content-Type:text/html" \
              -h "Cache-Control:private, max-age=0, no-transform" \
              "gs://$gs_path"/**.html > /dev/null 2>&1

          echo "Document link(s):" >> gerrit_comment.txt
          find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
              sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt

# To take advantage of this macro, have your build write
# out the file 'gerrit_comment.txt' with information to post
# back to gerrit and include this macro in the list of builders.
- builder:
    name: report-build-result-to-gerrit
    builders:
      - shell: |
          #!/bin/bash
          set -o errexit
          set -o pipefail
          set -o xtrace
          export PATH=$PATH:/usr/local/bin/
          if [[ -e gerrit_comment.txt ]] ; then
              echo
              echo "posting review comment to gerrit..."
              echo
              cat gerrit_comment.txt
              echo
              ssh -p 29418 gerrit.opnfv.org \
                  "gerrit review -p $GERRIT_PROJECT \
                   -m '$(cat gerrit_comment.txt)' \
                   $GERRIT_PATCHSET_REVISION \
                   --notify NONE"
          fi

- builder:
    name: remove-old-docs-from-opnfv-artifacts
    builders:
      - shell: |
          #!/bin/bash
          set -o errexit
          set -o pipefail
          set -o xtrace
          export PATH=$PATH:/usr/local/bin/

          [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]

          gs_path="artifacts.opnfv.org/$PROJECT/review/$GERRIT_CHANGE_NUMBER"

          if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
              echo
              echo "Deleting Out-of-dated Documents..."
              gsutil -m rm -r "gs://$gs_path"
          fi
          gs_path="artifacts.opnfv.org/review/$GERRIT_CHANGE_NUMBER"

          if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
              echo
              echo "Deleting Out-of-dated Documents..."
              gsutil -m rm -r "gs://$gs_path"
          fi

- builder:
    name: upload-review-docs
    builders:
      - upload-under-review-docs-to-opnfv-artifacts
      - report-build-result-to-gerrit

- builder:
    name: lint-init
    builders:
      - shell: |
          #!/bin/bash
          # Ensure we start with a clean environment
          rm -f bash-violation.log python-violation.log yaml-violation.log violation.log
          git --no-pager diff --diff-filter=MCRAT --name-only HEAD^1 > modified_files

- builder:
    name: lint-report
    builders:
      - shell: |
          #!/bin/bash
          if [[ -s violation.log ]]; then
              cat violation.log
              echo "Reporting lint result...."
              set -x
              msg="Found syntax error and/or coding style violation(s) in the files modified by your patchset."
              sed -i -e "1s#^#${msg}\n\n#" violation.log
              cmd="gerrit review -p $GERRIT_PROJECT -m \"$(cat violation.log)\" $GERRIT_PATCHSET_REVISION --notify NONE"
              ssh -p 29418 gerrit.opnfv.org "$cmd"

              # Make sure the caller job failed
              exit 1
          fi

- builder:
    name: lint-bash-code
    builders:
      - shell: |
          #!/bin/bash
          echo "Checking bash code..."
          for f in $(egrep '\.sh$' modified_files)
          do
              bash -n "$f" 2>> bash-violation.log
          done
          if [[ -s bash-violation.log ]]; then
              echo -e "Bash syntax error(s)\n---" >> violation.log
              sed -e 's/^/ /g' bash-violation.log >> violation.log
          fi

- builder:
    name: lint-python-code
    builders:
      - shell: |
          #!/bin/bash
          # Install python package
          sudo -H pip install "flake8==2.6.2"

          echo "Checking python code..."
          for f in $(egrep '\.py$' modified_files)
          do
              flake8 "$f" >> python-violation.log
          done
          if [[ -s python-violation.log ]]; then
              echo -e "Python violation(s)\n---" >> violation.log
              sed -e 's/^/ /g' python-violation.log >> violation.log
          fi

- builder:
    name: lint-yaml-code
    builders:
      - shell: |
          #!/bin/bash
          # sudo Install python packages
          sudo -H pip install "yamllint==1.8.2"

          echo "Checking yaml file..."
          for f in $(egrep '\.ya?ml$' modified_files)
          do
              yamllint "$f" >> yaml-violation.log
          done
          if [[ -s yaml-violation.log ]]; then
              echo -e "YAML violation(s)\n---" >> violation.log
              sed -e 's/^/ /g' yaml-violation.log >> violation.log
          fi

- builder:
    name: lint-all-code
    builders:
      - lint-init
      - lint-bash-code
      - lint-python-code
      - lint-yaml-code
      - lint-report

- builder:
    name: clean-workspace
    builders:
      - shell: |
          #!/bin/bash
          set -o errexit
          set -o nounset
          set -o pipefail
          sudo /bin/rm -rf "$WORKSPACE"

- builder:
    name: clean-workspace-log
    builders:
      - shell: |
          find $WORKSPACE -type f -name '*.log' | xargs rm -f

- builder:
    name: track-begin-timestamp
    builders:
      - shell: |
          echo "export TIMESTAMP_START="\'`date '+%Y-%m-%d %H:%M:%S.%3N'`\' > $WORKSPACE/installer_track.sh

- publisher:
    name: archive-artifacts
    publishers:
      - archive:
          artifacts: '{artifacts}'
          allow-empty: true
          fingerprint: true
          latest-only: true

- publisher:
    name: publish-coverage
    publishers:
      - cobertura:
          report-file: "coverage.xml"
          only-stable: "true"
          health-auto-update: "false"
          stability-auto-update: "false"
          zoom-coverage-chart: "true"
          targets:
            - files:
                healthy: 10
                unhealthy: 20
                failing: 30
            - method:
                healthy: 50
                unhealthy: 40
                failing: 30

# The majority of the email-ext plugin options are set to the default
# for this macro so they can be managed through Jenkins' global
# settings.
- publisher:
    name: email-jenkins-admins-on-failure
    publishers:
      - email-ext:
          content-type: text
          attach-build-log: true
          compress-log: true
          always: false
          failure: true
          send-to:
            - recipients

- publisher:
    name: 'report-provision-result'
    publishers:
      - postbuildscript:
          builders:
            - role: BOTH
              build-on:
                - SUCCESS
              build-steps:
                - shell: |
                    echo "export PROVISION_RESULT=PASS" >> $WORKSPACE/installer_track.sh
                    echo "export INSTALLER=$INSTALLER_TYPE" >> $WORKSPACE/installer_track.sh
                    echo "export TIMESTAMP_END="\'`date '+%Y-%m-%d %H:%M:%S.%3N'`\' >> $WORKSPACE/installer_track.sh
                - shell:
                    !include-raw: installer-report.sh
          mark-unstable-if-failed: true
      - postbuildscript:
          builders:
            - role: BOTH
              build-on:
                - ABORTED
                - FAILURE
                - NOT_BUILT
                - UNSTABLE
              build-steps:
                - shell: |
                    echo "export PROVISION_RESULT=FAIL" >> $WORKSPACE/installer_track.sh
                    echo "export INSTALLER=$INSTALLER_TYPE" >> $WORKSPACE/installer_track.sh
                    echo "export TIMESTAMP_END="\'`date '+%Y-%m-%d %H:%M:%S.%3N'`\' >> $WORKSPACE/installer_track.sh
                - shell:
                    !include-raw: installer-report.sh
          mark-unstable-if-failed: true