Allow java opts in WS scans
[releng/global-jjb.git] / jjb / lf-macros.yaml
1 ---
2 ############
3 # BUILDERS #
4 ############
5
6 # To take advantage of this macro, have your build write
7 # out the file 'gerrit_comment.txt' with information to post
8 # back to gerrit and include this macro in the list of builders.
9 - builder:
10     name: comment-to-gerrit
11     builders:
12       - shell: !include-raw: ../shell/comment-to-gerrit.sh
13
14 - builder:
15     name: lf-fetch-dependent-patches
16     builders:
17       - shell: !include-raw: ../shell/gerrit-fetch-dependencies.sh
18       - inject:
19           properties-file: $WORKSPACE/.dependency.properties
20
21 - builder:
22     name: lf-license-check
23     builders:
24       - inject:
25           properties-content: |
26             FILE_PATTERNS={file-patterns}
27             SPDX_DISABLE={spdx-disable}
28             LHC_VERSION={lhc-version}
29             LICENSE_EXCLUDE_PATHS={license-exclude-paths}
30             LICENSES_ALLOWED={licenses-allowed}
31       - shell: !include-raw-escape:
32           - ../shell/license-check.sh
33
34 - builder:
35     name: lf-infra-create-netrc
36     builders:
37       - inject:
38           properties-content: "SERVER_ID={server-id}"
39       - shell: !include-raw-escape: ../shell/create-netrc.sh
40
41 - builder:
42     name: lf-infra-docker-login
43     builders:
44       - lf-provide-maven-settings:
45           global-settings-file: "{global-settings-file}"
46           settings-file: "{settings-file}"
47       - shell: !include-raw-escape: ../shell/docker-login.sh
48       - lf-provide-maven-settings-cleanup
49
50 - builder:
51     name: lf-infra-gpg-verify-git-signature
52     # TODO: Verify signature after downloading users public key from a locally
53     # created repository instead of the public keymesh. This requires a process
54     # in place to get ODL developers public keys into a local repository without
55     # increasing the job thoughput.
56     builders:
57       - shell: !include-raw: ../shell/gpg-verify-git-signature.sh
58
59 - builder:
60     name: lf-infra-pre-build
61     builders:
62       - shell: !include-raw-escape: ../shell/python-tools-install.sh
63
64 - builder:
65     name: lf-infra-ship-logs
66     builders:
67       # Ensure no pre-existing .netrc files are overriding logs config
68       - lf-provide-maven-settings-cleanup
69       - config-file-provider:
70           files:
71             - file-id: "jenkins-log-archives-settings"
72               variable: "SETTINGS_FILE"
73       - lf-infra-create-netrc:
74           server-id: logs
75       - shell: !include-raw:
76           # Ensure python-tools are installed in case job template does not
77           # call the lf-infra-pre-build macro.
78           - ../shell/python-tools-install.sh
79       - shell: !include-raw:
80           - ../shell/logs-deploy.sh
81       - shell: !include-raw:
82           - ../shell/logs-clear-credentials.sh
83       - description-setter:
84           regexp: "^Build logs: .*"
85
86 - builder:
87     name: lf-infra-package-listing
88     builders:
89       - shell: !include-raw:
90           - ../shell/package-listing.sh
91
92 - builder:
93     name: lf-infra-packer-build
94     builders:
95       - conditional-step:
96           condition-kind: boolean-expression
97           condition-expression: "{openstack}"
98           steps:
99             - config-file-provider:
100                 files:
101                   - file-id: clouds-yaml
102                     target: "$HOME/.config/openstack/clouds.yaml"
103             - inject:
104                 properties-content: OS_CLOUD={openstack-cloud}
105       - config-file-provider:
106           files:
107             - file-id: "{packer-cloud-settings}"
108               variable: CLOUDENV
109       - inject:
110           properties-content: |
111             PACKER_PLATFORM={platform}
112             PACKER_TEMPLATE={template}
113             PACKER_VERSION={packer-version}
114             UPDATE_CLOUD_IMAGE={update-cloud-image}
115       - shell: !include-raw-escape:
116           - ../shell/packer-install.sh
117           - ../shell/packer-build.sh
118       - shell: !include-raw:
119           - ../shell/packer-clear-credentials.sh
120
121 - builder:
122     name: lf-infra-packer-validate
123     builders:
124       - conditional-step:
125           condition-kind: boolean-expression
126           condition-expression: "{openstack}"
127           steps:
128             - config-file-provider:
129                 files:
130                   - file-id: clouds-yaml
131                     target: "$HOME/.config/openstack/clouds.yaml"
132             - inject:
133                 properties-content: OS_CLOUD={openstack-cloud}
134       - config-file-provider:
135           files:
136             - file-id: "{packer-cloud-settings}"
137               variable: CLOUDENV
138       - inject:
139           properties-content: |
140             PACKER_VERSION={packer-version}
141       - shell: !include-raw-escape:
142           - ../shell/packer-install.sh
143           - ../shell/packer-validate.sh
144       - shell: !include-raw:
145           - ../shell/packer-clear-credentials.sh
146
147 - builder:
148     name: lf-infra-update-packer-images
149     builders:
150       - shell: !include-raw: ../shell/update-cloud-images.sh
151
152 - builder:
153     name: lf-infra-push-gerrit-patch
154     builders:
155       - inject:
156           properties-content: |
157             PROJECT={project}
158             GERRIT_COMMIT_MESSAGE={gerrit-commit-message}
159             GERRIT_HOST={gerrit-host}
160             GERRIT_TOPIC={gerrit-topic}
161             GERRIT_USER={gerrit-user}
162             REVIEWERS_EMAIL={reviewers-email}
163       - shell: !include-raw-escape: ../shell/gerrit-push-patch.sh
164
165 - builder:
166     name: lf-infra-sysstat
167     builders:
168       - shell: !include-raw:
169           - ../shell/sysstat.sh
170
171 - builder:
172     name: lf-jacoco-nojava-workaround
173     builders:
174       - shell: "mkdir -p $WORKSPACE/target/classes $WORKSPACE/jacoco/classes"
175
176 - builder:
177     name: lf-infra-deploy-maven-file
178     builders:
179       - lf-maven-install:
180           mvn-version: "{mvn-version}"
181       - lf-provide-maven-settings:
182           global-settings-file: "{global-settings-file}"
183           settings-file: "{settings-file}"
184       - inject:
185           properties-content: |
186             MAVEN_REPO_URL={maven-repo-url}
187             REPO_ID={repo-id}
188             GROUP_ID={group-id}
189             UPLOAD_FILES_PATH={upload-files-dir}
190       - shell: !include-raw-escape:
191           - ../shell/common-variables.sh
192           - ../shell/deploy-maven-file.sh
193       - lf-provide-maven-settings-cleanup
194
195 - builder:
196     name: lf-maven-central
197     builders:
198       - conditional-step:
199           condition-kind: boolean-expression
200           condition-expression: "{mvn-central}"
201           steps:
202             - lf-provide-maven-settings:
203                 global-settings-file: "{mvn-global-settings}"
204                 settings-file: "{mvn-settings}"
205             - lf-infra-create-netrc:
206                 server-id: "ossrh"
207             - inject:
208                 properties-content: "OSSRH_PROFILE_ID={ossrh-profile-id}"
209             - shell: !include-raw-escape: ../shell/maven-central.sh
210             - lf-provide-maven-settings-cleanup
211
212 - builder:
213     name: lf-maven-install
214     builders:
215       # Create a $HOME/.wgetrc to make the Maven download quiet.
216       - shell: 'echo "quiet=on" > "$HOME/.wgetrc"'
217       - maven-target:
218           maven-version: "{mvn-version}"
219           goals: "--version"
220       - shell: 'rm "$HOME/.wgetrc"'
221
222 - builder:
223     name: lf-provide-maven-settings
224     builders:
225       - config-file-provider:
226           files:
227             - file-id: "{global-settings-file}"
228               variable: "GLOBAL_SETTINGS_FILE"
229             - file-id: "{settings-file}"
230               variable: "SETTINGS_FILE"
231
232 - builder:
233     name: lf-pip-install
234     builders:
235       - inject:
236           properties-content: PIP_PACKAGES={pip-packages}
237       - shell: !include-raw-escape: ../shell/pip-install.sh
238
239 - builder:
240     name: lf-provide-maven-settings-cleanup
241     builders:
242       - shell: |
243           #!/bin/bash
244           set +e  # DO NOT cause build failure if any of the rm calls fail.
245
246           rm -f "$GLOBAL_SETTINGS_FILE" "$SETTINGS_FILE"
247
248           # In some cases we use the lf-provide-maven-settings macro to produce
249           # a "$HOME/.netrc" file containing credentials. Remove that file here
250           # too if it exists.
251           rm -f "$HOME/.netrc"
252
253           # DO NOT fail build if any of the above lines fail.
254           exit 0
255
256 - builder:
257     name: lf-rtd-trigger-build
258     builders:
259       - inject:
260           properties-content: |
261             RTD_BUILD_URL={rtd-build-url}
262             RTD_TOKEN={rtd-token}
263       - shell: !include-raw-escape: ../shell/rtd-trigger-build.sh
264
265 - builder:
266     name: lf-rtd-verify
267     builders:
268       - inject:
269           properties-content: |
270             DOC_DIR={doc-dir}
271             PYTHON={python-version}
272       - shell: !include-raw-escape: ../shell/tox-install.sh
273       - shell: !include-raw-escape: ../shell/rtd-verify.sh
274
275 - builder:
276     name: check-info-votes
277     builders:
278       - inject:
279           properties-content: JENKINS_SSH_CREDENTIAL={jenkins-ssh-credential}
280       - shell: !include-raw-escape: ../shell/check-info-votes.sh
281
282 - builder:
283     name: lf-release
284     builders:
285       - config-file-provider:
286           files:
287             - file-id: lftoolsini
288               target: "$HOME/.config/lftools/lftools.ini"
289       - shell: !include-raw: ../shell/release-job.sh
290
291 - builder:
292     name: lf-sigul-sign-dir
293     # Requires that Jenkins be configured with SIGUL_BRIDGE_IP as a global
294     # Environment variable
295     builders:
296       - conditional-step:
297           condition-kind: boolean-expression
298           condition-expression: "{sign-artifacts}"
299           steps:
300             - config-file-provider:
301                 files:
302                   - file-id: sigul-config
303                     variable: SIGUL_CONFIG
304                   - file-id: sigul-password
305                     variable: SIGUL_PASSWORD
306                   - file-id: sigul-pki
307                     variable: SIGUL_PKI
308             - shell: !include-raw-escape: ../shell/sigul-configuration.sh
309             - shell: !include-raw-escape: ../shell/sigul-install.sh
310             - inject:
311                 properties-content: |
312                   SIGN_DIR={sign-dir}
313                   SIGN_MODE={sign-mode}
314             - shell: !include-raw-escape:
315                 - ../shell/sigul-sign-dir.sh
316             - shell: !include-raw-escape: ../shell/sigul-configuration-cleanup.sh
317
318 - builder:
319     name: lf-infra-provide-docker-cleanup
320     builders:
321       - shell: |
322           #!/bin/bash
323           set +e  # DO NOT cause build failure if docker rmi fails
324           docker rmi -f $(docker images -a -q)
325           exit 0
326
327 - builder:
328     name: lf-infra-sonar
329     # Run a Sonar Jenkins Plugin
330     builders:
331       - sonar:
332           sonar-name: Sonar
333           scanner-name: SonarQubeScanner
334           task: "{sonar-task}"
335           project: "sonar-project.properties"
336           properties: "{sonar-properties}"
337           java-opts: "{sonar-java-opts}"
338           additional-arguments: "{sonar-additional-args}"
339
340 ##############
341 # PARAMETERS #
342 ##############
343
344 - parameter:
345     name: lf-clm-parameters
346     parameters:
347       - string:
348           name: NEXUS_IQ_STAGE
349           default: "{nexus-iq-stage}"
350           description: |
351             Stage the policy evaluation will be run against on the Nexus IQ Server.
352
353 - parameter:
354     name: lf-cmake-parameters
355     # Parameters useful in CMake builds.
356     parameters:
357       - string:
358           name: BUILD_DIR
359           default: "{build-dir}"
360           description: "Directory to build the project in."
361       - string:
362           name: CMAKE_OPTS
363           default: "{cmake-opts}"
364           description: |
365             Options to pass to CMAKE.
366             Example: -DCMAKE_INSTALL_PREFIX=$WORKSPACE/target/output
367       - string:
368           name: INSTALL_PREFIX
369           default: "{install-prefix}"
370           description: "Install prefix for C/C++ builds. Example: /usr/local"
371       - string:
372           name: MAKE_OPTS
373           default: "{make-opts}"
374           description: "Options to pass to make. Example: -j8"
375
376 - parameter:
377     name: lf-infra-maven-parameters
378     parameters:
379       - string:
380           name: M2_HOME
381           # Sets an env var for shell scripts to be able to call the dynamically
382           # installed maven without having to calculate the M2_HOME themselves.
383           default: "/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}"
384           description: "Maven selector to be used by shell scripts"
385       - string:
386           name: MAVEN_OPTS
387           default: "{mvn-opts}"
388           description: |
389             Maven Java opts. Example: -Xmx1024m -XX:MaxPermSize=256m
390       - string:
391           name: MAVEN_PARAMS
392           default: "{mvn-params}"
393           description: |
394             Maven parameters to pass to the mvn command.
395       - string:
396           name: MVN
397           # Sets an env var for shell scripts to be able to call the dynamically
398           # installed maven without having to calculate the path themselves.
399           # yamllint disable-line rule:line-length
400           default: "/w/tools/hudson.tasks.Maven_MavenInstallation/{mvn-version}/bin/mvn"
401           description: "Maven selector to be used by shell scripts"
402
403 - parameter:
404     name: lf-infra-openstack-parameters
405     parameters:
406       - string:
407           name: OS_CLOUD
408           default: "{os-cloud}"
409           description: |
410             The name of a cloud configuration in clouds.yaml. OS_CLOUD is a
411             variable name that is significant to openstack client as a
412             environment variable. Please refer to the documentation for
413             further details.
414             https://docs.openstack.org/developer/python-openstackclient/
415
416 - parameter:
417     name: lf-infra-parameters
418     # Standard parameters used in the LF CI environments. Gerrit variables are
419     # not used by GitHub projects, but defining them isn't harmful.
420     parameters:
421       - string:
422           name: PROJECT
423           default: "{project}"
424           description: |
425             Parameter to identify a SCM project to build. This is typically
426             the project repo path. For example: ofextensions/circuitsw
427       - string:
428           name: STREAM
429           default: "{stream}"
430           description: |
431             Stream is often set to the same name as 'branch' but can
432             sometimes be used as a name representing a project's release code
433             name.
434       - string:
435           name: GERRIT_PROJECT
436           default: "{project}"
437           description: |
438             Gerrit Trigger provided parameter to identify Gerrit project that
439             triggered the build. This is typically the project repo path as
440             exists in Gerrit. For example: ofextensions/circuitsw
441
442             If using Gerrit, in a manual build this should match the PROJECT
443             parameter above.
444       - string:
445           name: GERRIT_BRANCH
446           default: "{branch}"
447           description: |
448             Gerrit Trigger provided parameter to identify a Gerrit branch.
449
450             If using Gerrit, in a manual build override with the branch to
451             build against.
452       - string:
453           name: GERRIT_REFSPEC
454           default: "refs/heads/{branch}"
455           description: |
456             Gerrit Trigger provided parameter to identify a refspec to fetch
457             from Gerrit.
458
459             If using Gerrit, in a manual build override with a refspec.
460             https://git-scm.com/book/en/v2/Git-Internals-The-Refspec
461             For example: 'refs/heads/master'
462       - string:
463           name: sha1
464           default: "origin/{branch}"
465           description: |
466             GitHub PR Trigger provided parameter for specifying the commit
467             to checkout.
468
469             If using GitHub, in a manual build override with a branch path or
470             sha1 hash to a specific commit. For example: 'origin/master'
471
472 - parameter:
473     name: lf-infra-node-parameters
474     parameters:
475       - string:
476           name: NODE_DIR
477           default: "{node-dir}"
478           description: Path to a Node project directory.
479       - string:
480           name: NODE_VERSION
481           default: "{node-version}"
482           description: Version of NodeJS to install.
483
484 - parameter:
485     name: lf-infra-tox-parameters
486     parameters:
487       - string:
488           name: TOX_DIR
489           default: "{tox-dir}"
490           description: |
491             Path to directory containing tox.ini file.
492       - string:
493           name: TOX_ENVS
494           default: "{tox-envs}"
495           description: |
496             Tox environments to run build against.
497             Example: docs,py2,py3
498
499 - parameter:
500     name: lf-build-with-parameters-maven-release
501     parameters:
502       - string:
503           name: VERSION
504           default: ""
505           description: "This is the tag, Example: 1.0.0"
506       - string:
507           name: LOG_DIR
508           default: ""
509           description: "Log dir, example: project-maven-stage-master/17/"
510       - string:
511           name: DISTRIBUTION_TYPE
512           default: ""
513           description: "Set to maven for build with parametes"
514       - bool:
515           name: USE_RELEASE_FILE
516           default: "{use-release-file}"
517           description: "Set to False for job built with parameters"
518
519 ##############
520 # PROPERTIES #
521 ##############
522
523 - property:
524     name: lf-infra-properties
525     properties:
526       - build-discarder:
527           # Allow build data to be stored at a length configured by the
528           # downstream project.
529           days-to-keep: "{build-days-to-keep}"
530           # Do not allow artifacts to be stored in Jenkins.
531           artifact-num-to-keep: 0
532
533 ##############
534 # PUBLISHERS #
535 ##############
536
537 - publisher:
538     name: lf-jacoco-report
539     publishers:
540       - jacoco:
541           exec-pattern: "**/**.exec"
542           class-pattern: "**/classes"
543           source-pattern: "**/src/main/java"
544           # yamllint disable-line rule:line-length
545           exclusion-pattern: "**/gen/**,**/generated-sources/**,**/yang-gen**,**/pax/**"
546           status-update: true
547           targets:
548             - branch:
549                 healthy: 10
550                 unhealthy: 20
551             - method:
552                 healthy: 50
553                 unhealthy: 40
554
555 - publisher:
556     name: lf-infra-publish
557     # lf-infra macro to finish up a build.
558     #
559     # Handles the following:
560     #   - Shipping logs to Nexus logs site repository
561     #   - Cleanup workspace
562     publishers:
563       - postbuildscript:
564           builders:
565             - role: BOTH
566               build-on:
567                 - ABORTED
568                 - FAILURE
569                 - NOT_BUILT
570                 - SUCCESS
571                 - UNSTABLE
572               build-steps:
573                 - lf-infra-sysstat
574                 - lf-infra-package-listing
575                 - lf-infra-ship-logs
576           mark-unstable-if-failed: true
577       - workspace-cleanup:
578           exclude:
579             # Do not clean up *.jenkins-trigger files for jobs that use a
580             # properties file as input for triggering another build.
581             - "**/*.jenkins-trigger"
582           fail-build: false
583
584 - publisher:
585     name: lf-infra-publish-windows
586     # lf-infra macro to finish up a build.
587     #
588     # Handles the following:
589     #   - Shipping logs to Nexus logs site repository
590     #   - Cleanup workspace
591     publishers:
592       # TODO: RELENG-1228 Develop log shipping script for Windows systems
593       # - postbuildscript:
594       #     builders:
595       #       - role: BOTH
596       #         build-on:
597       #           - ABORTED
598       #           - FAILURE
599       #           - NOT_BUILT
600       #           - SUCCESS
601       #           - UNSTABLE
602       #         build-steps:
603       #           - lf-infra-ship-logs-windows
604       #     mark-unstable-if-failed: true
605       - workspace-cleanup:
606           exclude:
607             # Do not clean up *.jenkins-trigger files for jobs that use a
608             # properties file as input for triggering another build.
609             - "**/*.jenkins-trigger"
610           fail-build: false
611
612 #######
613 # SCM #
614 #######
615
616 - scm:
617     name: lf-infra-gerrit-scm
618     scm:
619       - git:
620           credentials-id: "{jenkins-ssh-credential}"
621           url: "{git-url}"
622           refspec: "{refspec}"
623           branches:
624             - "refs/heads/{branch}"
625           skip-tag: true
626           wipe-workspace: true
627           submodule:
628             disable: "{submodule-disable}"
629             recursive: "{submodule-recursive}"
630             timeout: "{submodule-timeout}"
631           choosing-strategy: "{choosing-strategy}"
632
633 - scm:
634     name: lf-infra-github-scm
635     scm:
636       - git:
637           credentials-id: "{jenkins-ssh-credential}"
638           url: "{url}"
639           refspec: "{refspec}"
640           branches:
641             - "{branch}"
642           skip-tag: true
643           wipe-workspace: true
644           submodule:
645             disable: "{submodule-disable}"
646             recursive: "{submodule-recursive}"
647             timeout: "{submodule-timeout}"
648           choosing-strategy: "{choosing-strategy}"
649
650 ############
651 # WRAPPERS #
652 ############
653
654 - wrapper:
655     name: lf-infra-wrappers-common
656     wrappers:
657       - mask-passwords
658       - timeout:
659           type: absolute
660           timeout: "{build-timeout}"
661           timeout-var: "BUILD_TIMEOUT"
662           fail: true
663       - timestamps
664       - openstack:
665           single-use: true
666
667 - wrapper:
668     name: lf-infra-wrappers
669     wrappers:
670       - lf-infra-wrappers-common:
671           build-timeout: "{build-timeout}"
672       - config-file-provider:
673           files:
674             - file-id: npmrc
675               target: "$HOME/.npmrc"
676             - file-id: pipconf
677               target: "$HOME/.config/pip/pip.conf"
678       - ssh-agent-credentials:
679           users:
680             - "{jenkins-ssh-credential}"
681
682 - wrapper:
683     name: lf-infra-wrappers-windows
684     wrappers:
685       - lf-infra-wrappers-common:
686           build-timeout: "{build-timeout}"