Fix: Update lf-infra-sonar macro to use JDK version
[releng/global-jjb.git] / docs / jjb / lf-macros.rst
1 #############
2 Global Macros
3 #############
4
5 Builders
6 ========
7
8 comment-to-gerrit
9 -----------------
10
11 This macro will post a comment to the gerrit patchset if the build
12 creates a file named gerrit_comment.txt
13 To use this macro add it to the list of builders.
14
15 lf-ansible-config-file-provider
16 -------------------------------
17
18 Provisions files required by the ansible, namely
19 "~/.ansible/ansible.cfg" in the Jenkins home directory.
20
21 lf-fetch-dependent-patches
22 --------------------------
23
24 Fetch all patches provided via comment trigger
25
26 This macro will fetch all patches provided via comment trigger and will
27 create a list of projects from those patches via environment variable
28 called ``DEPENDENCY_BUILD_ORDER`` to build projects in the specified order.
29 Order calculated by the first patch instance for a project in the patch list.
30
31 lf-license-check
32 ----------------
33
34 Checks files for
35
36 :Required parameters:
37
38     :file-patterns: Space-separated list of file patterns to scan.
39         For example: \*.go \*.groovy \*.java \*.py \*.sh
40     :spdx-disable: Disable the SPDX-Identifier checker.
41     :lhc-version: Version of LHC to use.
42     :license-exclude-paths: Comma-separated list of paths to exclude from the
43         license checker. Matches the paths defined here using a contains rule,
44         we recommend you to configure as precisely as possible. For example
45         a path of '/src/generated/' will search as '**/src/generated/**'.
46         Example: org/opendaylight/yang/gen,protobuff/messages
47     :licenses-allowed: Comma-separated list of allowed licenses.
48         For example: Apache-2.0,EPL-1.0,MIT
49
50 lf-infra-capture-instance-metadata
51 ----------------------------------
52
53 Capture instance metadata.
54
55 lf-infra-create-netrc
56 ---------------------
57
58 Create a ~/.netrc file from a Maven settings.xml
59
60 :Required parameters:
61
62     :server-id: The id of a server as defined in settings.xml.
63
64 :Optional parameters:
65
66     :ALT_NEXUS_SERVER: URL of custom nexus server.
67         If set this will take precedence.
68         Use this to point at nexus3.$PROJECTDOMAIN
69         for example.
70
71 lf-infra-deploy-maven-file
72 --------------------------
73
74 Deploy files to a repository.
75
76 :Required parameters:
77
78     :global-settings-file: Global settings file to use.
79     :group-id: Group ID of the repository.
80     :maven-repo-url: URL of a Maven repository to upload to.
81     :mvn-version: Version of Maven to use.
82     :repo-id: Repository ID
83     :settings-file: Maven settings file to use.
84     :upload-files-dir: Path to directory containing one or more files
85
86 lf-infra-docker-login
87 ---------------------
88
89 Login into a custom hosted docker registry and / or docker.io
90
91 The Jenkins system should have the following global variables defined
92
93 :Environment variables:
94
95     :DOCKER_REGISTRY: The DNS address of the registry (IP or FQDN)
96         ex: nexus3.example.com (GLOBAL variable)
97
98     :REGISTRY_PORTS: Required when setting ``DOCKER_REGISTRY``. Space-separated
99         list of the registry ports to login to. ex: 10001 10002 10003 10004
100         (GLOBAL variable)
101
102     :DOCKERHUB_EMAIL: If set, then the job will attempt to login to DockerHub
103         (docker.io). Set to the email address for the credentials that will
104         get looked up. Returns the _first_ credential from the maven settings
105         file for DockerHub. (GLOBAL variable)
106
107 lf-infra-gpg-verify-git-signature
108 ---------------------------------
109
110 Verify gpg signature of the latest commit message in $WORKSPACE.
111 This command assumes that $WORKSPACE is a git repo.
112
113 lf-infra-pre-build
114 ------------------
115
116 Macro that runs before all builders to prepare the system for job use.
117
118 lf-infra-package-listing
119 ------------------------
120
121 Lists distro level packages.
122
123 lf-infra-packer-build
124 ---------------------
125
126 Run `packer build` to build system images.
127
128 :Required parameters:
129
130     :openstack: Packer template uses an OpenStack builder (true|false).
131     :openstack-cloud: Sets OS_CLOUD variable to the value of this parameter.
132     :packer-version: Version of packer to use.
133     :platform: Build platform as found in the vars directory.
134     :template: Packer template to build as found in the templates directory.
135
136 :Optional parameters:
137
138     :update-cloud-image: Submit a change request to update new built cloud
139         image to Jenkins.
140
141 lf-infra-packer-validate
142 ------------------------
143
144 Run ``packer validate`` to verify packer configuration.
145
146 :Required parameters:
147
148     :openstack: Packer template uses an OpenStack builder (true|false).
149     :openstack-cloud: Sets OS_CLOUD variable to the value of this parameter.
150     :packer-cloud-settings: Cloud configuration file. Loaded on the build
151         server as CLOUDENV environment variable.
152     :packer-version: Version of packer to use.
153
154 lf-infra-push-gerrit-patch
155 --------------------------
156
157 Push a change through a Jenkins job to a Gerrit repository in an automated
158 way using git-review.
159
160 :Required parameters:
161
162     :gerrit-commit-message: Commit message to assign.
163     :gerrit-host: Gerrit hostname.
164     :gerrit-topic: Gerrit topic.
165     :gerrit-user: Gerrit user-id used for submitting the change.
166     :reviewers-email: Reviewers email. Space-separated list of
167         email addresses to CC on the patch.
168     :project: Gerrit project name.
169
170 .. _lf-infra-ship-logs:
171
172 lf-infra-ship-logs
173 ------------------
174
175 Gather and deploy logs to a log server.
176
177 lf-infra-sysstat
178 ----------------
179
180 Retrieves system stats.
181
182 lf-infra-update-packer-images
183 -----------------------------
184
185 Find and update the new built cloud image{s} in the ci-management source
186 repository.
187
188
189 lf-jacoco-nojava-workaround
190 ---------------------------
191
192 Workaround for Jenkins not able to find Java in JaCoCo runs.
193
194 .. _lf-maven-central:
195
196 lf-maven-central
197 ----------------
198
199 Publish artifacts to OSSRH (Maven Central) staging.
200
201 Requires that the project's settings.xml contains a ServerId 'ossrh' with the
202 credentials for the project's OSSRH account.
203
204 This macro assumes the directory ``$WORKSPACE/m2repo`` contains a Maven 2
205 repository which is to upload to OSSRH.
206
207 :Required parameters:
208
209     :mvn-central: Set to ``true`` to upload to mvn-central. (true|false)
210     :mvn-global-settings: The name of the Maven global settings to use for
211         Maven configuration. (default: global-settings)
212     :mvn-settings: The name of settings file containing credentials for the
213         project.
214     :ossrh-profile-id: Nexus staging profile ID as provided by OSSRH.
215
216 .. literalinclude:: ../../.jjb-test/lf-macros/lf-maven-central-minimal.yaml
217    :language: yaml
218
219 .. _lf-maven-install:
220
221 lf-maven-install
222 ----------------
223
224 Call maven-target builder with a goal of ``--version`` to force Jenkins to
225 install the declared version of Maven. Use this as a preparation step for
226 any shell scripts that want to use Maven.
227
228 :Required parameters:
229
230     :mvn-version: Version of Maven to install.
231
232 lf-packagecloud-file-provider
233 -----------------------------
234
235 Provisions files required by the Ruby gem package_cloud, namely
236 ".packagecloud" and "packagecloud_api" in the Jenkins home directory.
237
238 lf-packagecloud-push
239 --------------------
240
241 Pushes DEB/RPM package files to PackageCloud using the Ruby gem package_cloud.
242
243 :Required parameters:
244
245     :build-dir: Directory with deb/rpm files to push
246     :debian-distribution-versions: list of DEB package distro/version strings
247         separated by space; example: ubuntu/bionic debian/stretch
248     :packagecloud-account: PackageCloud account ID; example: oran
249     :packagecloud-repo: PackageCloud repository; example: master, staging
250     :rpm-distribution-versions: list of RPM package distro/version strings
251         separated by space; example: el/4 el/5
252
253 lf-pip-install
254 --------------
255
256 Call pip install to install packages into a virtualenv located in
257 /tmp/v/VENV
258
259 .. note:: Uses the first package listed in PIP_PACKAGES as the VENV name.
260
261 .. _lf-provide-maven-settings:
262
263 lf-provide-maven-settings
264 -------------------------
265
266 Push a global settings and user settings maven files to the build node.
267
268 lf-provide-maven-settings-cleanup
269 ---------------------------------
270
271 Cleanup maven ``settings.xml`` configuration. Set at the end of any macros that
272 calls the
273 :ref:`lf-provide-maven-settings <lf-provide-maven-settings>` macro.
274
275 lf-rtd-trigger-build
276 --------------------
277
278 Script to trigger a build on http://readthedocs.org
279
280 lf-rtd-verify
281 -------------
282
283 ReadTheDocs verify script. Installs and runs tox.
284
285 :Required parameters:
286
287     :doc-dir: Document directory.
288     :python-version: Python version.
289
290 lf-rtdv3-build
291 ---------------
292
293 Read the docs scripts that leverage the new Read the Docs v3 api
294 `RTD v3 API <https://docs.readthedocs.io/en/stable/api/v3.html>`_
295 Runs tox to verify that the docs are good and then runs the RTDv3 shell script.
296 This script handles creating projects as needed, assiging subprojects to the main
297 read the docs project and triggering builds to update the documentation.
298 Jobs will run but skip verify bits until a ``.readthedocs.yaml`` exists in the
299 root of their repository.
300
301
302 check-info-votes
303 ----------------
304
305 Validates votes on a changes to ``INFO.yaml``.
306
307 lf-release
308 ----------
309
310 releases lftools.ini (required)
311 needed to push to nexus.
312
313 [nexus]
314 username=
315 password=
316
317 Then runs ../shell/release-job.sh
318
319
320 lf-sigul-sign-dir
321 -----------------
322
323 Use Sigul to sign a directory via {sign-dir}.
324
325 Requires ``SIGUL_BRIDGE_IP`` configured as a global envvar.
326
327 :Required Parameters:
328     :sign-artifacts: Set ``true`` to sign artifacts with Sigul.
329     :sign-dir: Directory to sign.
330     :sign-mode: serial|parallel
331
332 lf-infra-provide-docker-cleanup
333 -------------------------------
334
335 Forcefully removes all docker images.
336
337 lf-infra-sonar
338 ---------------
339
340 Runs Jenkins SonarQube plug-in.
341
342 Requires ``SonarQube Scanner for Jenkins``
343
344 .. note::
345
346     Optionally, set Sonar properties directly in the job definition by
347     setting the sonar-project-file to ``""`` and adding all properties under
348     ``sonar-properties``.
349
350 :Optional Parameters:
351     :sonar-task: Sonar task to run. (default: "")
352     :sonar-project-file: The filename for the project's properties
353         (default: "sonar-project.properties")
354     :sonar-properties: Sonar configuration properties. (default: "")
355     :sonar-java-opts: JVM options. (default: "")
356     :sonar-additional-args: Additional command line arguments. (default: "")
357     :sonar-jdk: JDK version to use. (default: openjdk17)
358
359 lf-infra-sonar-with-prescan
360 ---------------------------
361
362 Runs Jenkins SonarQube plug-in after a pre-scan builder.
363
364 Requires ``SonarQube Scanner for Jenkins``
365
366 .. note::
367
368     Optionally, set Sonar properties directly in the job definition by
369     setting the sonar-project-file to ``""`` and adding all properties under
370     ``sonar-properties``.
371
372 :Required Parameters:
373     :lf-sonar-prescan: A builder that will run before the Sonar scan.
374
375 :Optional Parameters:
376     :sonar-task: Sonar task to run. (default: "")
377     :sonar-project-file: The filename for the project's properties
378         (default: "sonar-project.properties")
379     :sonar-properties: Sonar configuration properties. (default: "")
380     :sonar-java-opts: JVM options. (default: "")
381     :sonar-additional-args: Additional command line arguments. (default: "")
382
383 lf-infra-pipeline-verify
384 ------------------------
385
386 Verify a Jenkins pipeline by linting it and ensuring that it cannot run on the
387 Jenkins master.
388
389 Parameters
390 ==========
391
392 lf-autotools-parameters
393 -----------------------
394
395 Provides parameters needed by configure and make. Use in any jobs that need to
396 call the ``configure && make`` pattern.
397
398 lf-clm-parameters
399 -----------------
400
401 Provides the policy evaluation stage to run against Nexus IQ Server.
402 Valid values include: 'build', 'stage-release', 'operate'.
403
404 lf-cmake-parameters
405 -------------------
406
407 Provides parameters required by CMake. Use in any jobs that need to call the
408 ``cmake && make && make install`` pattern.
409
410 lf-infra-maven-parameters
411 -------------------------
412
413 Provides parameters required by Maven. Use in any jobs that need to call the
414 ``mvn`` CLI.
415
416 lf-infra-openstack-parameters
417 -----------------------------
418
419 Provides parameters needed by OpenStack client CLI. Use in jobs that need to
420 call the openstack cli.
421
422 :Required Parameters:
423
424     :os-cloud: Configures ``OS_CLOUD`` envvar as used by openstack cli.
425
426 lf-infra-parameters
427 -------------------
428
429 Standard parameters used in the LF CI environments. GitHub projects will ignore
430 the Gerrit variables and vice-versa, so defining them is not harmful. Use in
431 every job template.
432
433 lf-infra-node-parameters
434 ------------------------
435
436 Provides parameters needed by NodeJS and NPM. Use in any jobs that need to run
437 NodeJS or NPM.
438
439 lf-infra-sonar-cli-parameters
440 -----------------------------
441
442 Provides parameters needed by Python jobs to run the SonarCloud CLI.
443
444 lf-infra-tox-parameters
445 -----------------------
446
447 Provides parameters required by python-tox. Use in any jobs that need to run
448 `tox <https://tox.readthedocs.io>`.
449
450
451 lf-build-with-parameters-maven-release
452 --------------------------------------
453
454 Provides parameters needed for maven release jobs 'build with parameters'.
455
456 Properties
457 ==========
458
459 lf-infra-properties
460 -------------------
461
462 Configures the build-discarder plugin for Jenkins with the recommended lf-infra
463 settings. We recommend to include in all job-templates.
464
465 Publishers
466 ==========
467
468 lf-jacoco-report
469 ----------------
470
471 Provides basic configuration for the JaCoCo plugin.
472
473 lf-infra-publish
474 ----------------
475
476 Provides basic lf-infra recommended publisher configurations for use in all job
477 templates. The purpose of this trigger is to gather package listing, instance
478 metadata, sar reports, build logs and copy them to a log server.
479
480 lf-infra-publish-windows
481 ------------------------
482
483 Windows publisher for use at the end of Windows job templates. Takes care of
484 cleaning out the workspace at the end of a job.
485
486 SCM
487 ===
488
489 lf-infra-gerrit-scm
490 -------------------
491
492 Basic SCM configuration for Gerrit based projects.
493
494 :Required parameters:
495
496     :submodule-timeout: Timeout (in minutes) for checkout operation.
497         (default: 10)
498     :submodule-disable: Disable submodule checkout operation.
499         (default: false)
500
501 lf-infra-github-scm
502 -------------------
503
504 Basic SCM configuration for GitHub based projects.
505
506 On the `branch` variable you can assign ``$sha1`` or ``$ghprbActualCommit``
507 as the value.  This will enable the jobs to trigger via the GHPRB plugin.
508
509 :Required parameters:
510
511     :submodule-timeout: Timeout (in minutes) for checkout operation.
512         (default: 10)
513     :submodule-disable: Disable submodule checkout operation.
514         (default: false)
515
516 Wrappers
517 ========
518
519 lf-infra-wrappers-common
520 ------------------------
521
522 Provides lf-infra recommended wrappers for use in every job-template. Include
523 this wrapper when creating more specific platform wrappers to ensure they pick
524 up the common settings.
525
526 lf-infra-wrappers
527 -----------------
528
529 Provides lf-infra recommended wrappers for use in every job-template targetting
530 Linux systems.
531
532 This wrapper requires a managed file named ``npmrc`` to exist in Jenkins. The
533 main use case here is to point to a npm proxy, on Nexus for example. Set the
534 file type to "Custom file".  You can set any npmrc settings in it,
535 documentation on npm configuration is available at
536 <https://docs.npmjs.com/files/npmrc>. If you are not using npm then create an
537 empty file.
538
539 Example npmrc:
540
541 .. code-block:: bash
542
543    registry=https://nexus3.onap.org/repository/npm.public/
544
545 lf-infra-wrappers-windows
546 -------------------------
547
548 Provides lf-infra recommended wrappers for use in every job-template targetting
549 Windows systems.
550
551
552 global-jjb-email-notification
553 -----------------------------
554
555 Provides a publisher macro that ties into the lf-openstack-cron job
556 to alert admins if this job fails.