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