0ad15060f49fd25488a4aea328d64696f8e59add
[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
358 lf-infra-sonar-with-prescan
359 ---------------------------
360
361 Runs Jenkins SonarQube plug-in after a pre-scan builder.
362
363 Requires ``SonarQube Scanner for Jenkins``
364
365 .. note::
366
367     Optionally, set Sonar properties directly in the job definition by
368     setting the sonar-project-file to ``""`` and adding all properties under
369     ``sonar-properties``.
370
371 :Required Parameters:
372     :lf-sonar-prescan: A builder that will run before the Sonar scan.
373
374 :Optional Parameters:
375     :sonar-task: Sonar task to run. (default: "")
376     :sonar-project-file: The filename for the project's properties
377         (default: "sonar-project.properties")
378     :sonar-properties: Sonar configuration properties. (default: "")
379     :sonar-java-opts: JVM options. (default: "")
380     :sonar-additional-args: Additional command line arguments. (default: "")
381
382 lf-infra-pipeline-verify
383 ------------------------
384
385 Verify a Jenkins pipeline by linting it and ensuring that it cannot run on the
386 Jenkins master.
387
388 Parameters
389 ==========
390
391 lf-autotools-parameters
392 -----------------------
393
394 Provides parameters needed by configure and make. Use in any jobs that need to
395 call the ``configure && make`` pattern.
396
397 lf-clm-parameters
398 -----------------
399
400 Provides the policy evaluation stage to run against Nexus IQ Server.
401 Valid values include: 'build', 'stage-release', 'operate'.
402
403 lf-cmake-parameters
404 -------------------
405
406 Provides parameters required by CMake. Use in any jobs that need to call the
407 ``cmake && make && make install`` pattern.
408
409 lf-infra-maven-parameters
410 -------------------------
411
412 Provides parameters required by Maven. Use in any jobs that need to call the
413 ``mvn`` CLI.
414
415 lf-infra-openstack-parameters
416 -----------------------------
417
418 Provides parameters needed by OpenStack client CLI. Use in jobs that need to
419 call the openstack cli.
420
421 :Required Parameters:
422
423     :os-cloud: Configures ``OS_CLOUD`` envvar as used by openstack cli.
424
425 lf-infra-parameters
426 -------------------
427
428 Standard parameters used in the LF CI environments. GitHub projects will ignore
429 the Gerrit variables and vice-versa, so defining them is not harmful. Use in
430 every job template.
431
432 lf-infra-node-parameters
433 ------------------------
434
435 Provides parameters needed by NodeJS and NPM. Use in any jobs that need to run
436 NodeJS or NPM.
437
438 lf-infra-sonar-cli-parameters
439 -----------------------------
440
441 Provides parameters needed by Python jobs to run the SonarCloud CLI.
442
443 lf-infra-tox-parameters
444 -----------------------
445
446 Provides parameters required by python-tox. Use in any jobs that need to run
447 `tox <https://tox.readthedocs.io>`.
448
449
450 lf-build-with-parameters-maven-release
451 --------------------------------------
452
453 Provides parameters needed for maven release jobs 'build with parameters'.
454
455 Properties
456 ==========
457
458 lf-infra-properties
459 -------------------
460
461 Configures the build-discarder plugin for Jenkins with the recommended lf-infra
462 settings. We recommend to include in all job-templates.
463
464 Publishers
465 ==========
466
467 lf-jacoco-report
468 ----------------
469
470 Provides basic configuration for the JaCoCo plugin.
471
472 lf-infra-publish
473 ----------------
474
475 Provides basic lf-infra recommended publisher configurations for use in all job
476 templates. The purpose of this trigger is to gather package listing, instance
477 metadata, sar reports, build logs and copy them to a log server.
478
479 lf-infra-publish-windows
480 ------------------------
481
482 Windows publisher for use at the end of Windows job templates. Takes care of
483 cleaning out the workspace at the end of a job.
484
485 SCM
486 ===
487
488 lf-infra-gerrit-scm
489 -------------------
490
491 Basic SCM configuration for Gerrit based projects.
492
493 :Required parameters:
494
495     :submodule-timeout: Timeout (in minutes) for checkout operation.
496         (default: 10)
497     :submodule-disable: Disable submodule checkout operation.
498         (default: false)
499
500 lf-infra-github-scm
501 -------------------
502
503 Basic SCM configuration for GitHub based projects.
504
505 On the `branch` variable you can assign ``$sha1`` or ``$ghprbActualCommit``
506 as the value.  This will enable the jobs to trigger via the GHPRB plugin.
507
508 :Required parameters:
509
510     :submodule-timeout: Timeout (in minutes) for checkout operation.
511         (default: 10)
512     :submodule-disable: Disable submodule checkout operation.
513         (default: false)
514
515 Wrappers
516 ========
517
518 lf-infra-wrappers-common
519 ------------------------
520
521 Provides lf-infra recommended wrappers for use in every job-template. Include
522 this wrapper when creating more specific platform wrappers to ensure they pick
523 up the common settings.
524
525 lf-infra-wrappers
526 -----------------
527
528 Provides lf-infra recommended wrappers for use in every job-template targetting
529 Linux systems.
530
531 This wrapper requires a managed file named ``npmrc`` to exist in Jenkins. The
532 main use case here is to point to a npm proxy, on Nexus for example. Set the
533 file type to "Custom file".  You can set any npmrc settings in it,
534 documentation on npm configuration is available at
535 <https://docs.npmjs.com/files/npmrc>. If you are not using npm then create an
536 empty file.
537
538 Example npmrc:
539
540 .. code-block:: bash
541
542    registry=https://nexus3.onap.org/repository/npm.public/
543
544 lf-infra-wrappers-windows
545 -------------------------
546
547 Provides lf-infra recommended wrappers for use in every job-template targetting
548 Windows systems.
549
550
551 global-jjb-email-notification
552 -----------------------------
553
554 Provides a publisher macro that ties into the lf-openstack-cron job
555 to alert admins if this job fails.