c4bda39c013f0f0532bb80319acf3ea354e739a9
[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-gerrit-event-comment-text-parameter
411 --------------------------------------
412
413 Provides the value for GERRIT_EVENT_COMMENT_TEXT,
414 needed for jobs triggerable via a gerrit comment
415 when starting them via "Build with parameters" instead.
416 For example when testing jobs on Sandbox.
417
418 lf-infra-maven-parameters
419 -------------------------
420
421 Provides parameters required by Maven. Use in any jobs that need to call the
422 ``mvn`` CLI.
423
424 lf-infra-openstack-parameters
425 -----------------------------
426
427 Provides parameters needed by OpenStack client CLI. Use in jobs that need to
428 call the openstack cli.
429
430 :Required Parameters:
431
432     :os-cloud: Configures ``OS_CLOUD`` envvar as used by openstack cli.
433
434 lf-infra-parameters
435 -------------------
436
437 Standard parameters used in the LF CI environments. GitHub projects will ignore
438 the Gerrit variables and vice-versa, so defining them is not harmful. Use in
439 every job template.
440
441 lf-infra-node-parameters
442 ------------------------
443
444 Provides parameters needed by NodeJS and NPM. Use in any jobs that need to run
445 NodeJS or NPM.
446
447 lf-infra-sonar-cli-parameters
448 -----------------------------
449
450 Provides parameters needed by Python jobs to run the SonarCloud CLI.
451
452 lf-infra-tox-parameters
453 -----------------------
454
455 Provides parameters required by python-tox. Use in any jobs that need to run
456 `tox <https://tox.readthedocs.io>`.
457
458
459 lf-build-with-parameters-maven-release
460 --------------------------------------
461
462 Provides parameters needed for maven release jobs 'build with parameters'.
463
464 Properties
465 ==========
466
467 lf-infra-properties
468 -------------------
469
470 Configures the build-discarder plugin for Jenkins with the recommended lf-infra
471 settings. We recommend to include in all job-templates.
472
473 Publishers
474 ==========
475
476 lf-jacoco-report
477 ----------------
478
479 Provides basic configuration for the JaCoCo plugin.
480
481 lf-infra-publish
482 ----------------
483
484 Provides basic lf-infra recommended publisher configurations for use in all job
485 templates. The purpose of this trigger is to gather package listing, instance
486 metadata, sar reports, build logs and copy them to a log server.
487
488 lf-infra-publish-windows
489 ------------------------
490
491 Windows publisher for use at the end of Windows job templates. Takes care of
492 cleaning out the workspace at the end of a job.
493
494 SCM
495 ===
496
497 lf-infra-gerrit-scm
498 -------------------
499
500 Basic SCM configuration for Gerrit based projects.
501
502 :Required parameters:
503
504     :submodule-timeout: Timeout (in minutes) for checkout operation.
505         (default: 10)
506     :submodule-disable: Disable submodule checkout operation.
507         (default: false)
508
509 lf-infra-github-scm
510 -------------------
511
512 Basic SCM configuration for GitHub based projects.
513
514 On the `branch` variable you can assign ``$sha1`` or ``$ghprbActualCommit``
515 as the value.  This will enable the jobs to trigger via the GHPRB plugin.
516
517 :Required parameters:
518
519     :submodule-timeout: Timeout (in minutes) for checkout operation.
520         (default: 10)
521     :submodule-disable: Disable submodule checkout operation.
522         (default: false)
523
524 Wrappers
525 ========
526
527 lf-infra-wrappers-common
528 ------------------------
529
530 Provides lf-infra recommended wrappers for use in every job-template. Include
531 this wrapper when creating more specific platform wrappers to ensure they pick
532 up the common settings.
533
534 lf-infra-wrappers
535 -----------------
536
537 Provides lf-infra recommended wrappers for use in every job-template targetting
538 Linux systems.
539
540 This wrapper requires a managed file named ``npmrc`` to exist in Jenkins. The
541 main use case here is to point to a npm proxy, on Nexus for example. Set the
542 file type to "Custom file".  You can set any npmrc settings in it,
543 documentation on npm configuration is available at
544 <https://docs.npmjs.com/files/npmrc>. If you are not using npm then create an
545 empty file.
546
547 Example npmrc:
548
549 .. code-block:: bash
550
551    registry=https://nexus3.onap.org/repository/npm.public/
552
553 lf-infra-wrappers-windows
554 -------------------------
555
556 Provides lf-infra recommended wrappers for use in every job-template targetting
557 Windows systems.
558
559
560 global-jjb-email-notification
561 -----------------------------
562
563 Provides a publisher macro that ties into the lf-openstack-cron job
564 to alert admins if this job fails.