Convert distribution-check to regular jjb template
[releng/builder.git] / docs / jenkins.rst
1 Jenkins
2 =======
3
4 The `Release Engineering Project <releng-wiki_>`_ consolidates the Jenkins jobs from
5 project-specific VMs to a single Jenkins server. Each OpenDaylight project
6 has a tab for their jobs on the `jenkins-master`_. The system utilizes
7 `Jenkins Job Builder <jjb-docs_>`_ for the creation and management of the
8 Jenkins jobs.
9
10 Sections:
11
12 .. contents::
13    :depth: 3
14    :local:
15
16 New Project Quick Start
17 -----------------------
18
19 .. note::
20
21     We will be revamping releng/builder in the near future to simplify
22     the below process.
23
24 This section attempts to provide details on how to get going as a new project
25 quickly with minimal steps. The rest of the guide should be read and understood
26 by those who need to create and contribute new job types that is not already
27 covered by the existing job templates provided by OpenDaylight's JJB repo.
28
29 As a new project you will be mainly interested in getting your jobs to appear
30 in the jenkins-master_ silo and this can be achieved by simply creating 2 files
31 project.cfg and project.yaml in the releng/builder project's jjb directory.
32
33 .. code-block:: bash
34
35     git clone https://git.opendaylight.org/gerrit/releng/builder
36     cd builder
37     mkdir jjb/<new-project>
38
39 Where <new-project> should be the same name as your project's git repo in
40 Gerrit. So if your project is called "aaa" then create a new jjb/aaa directory.
41
42 Next we will create <new-project>.yaml as follows:
43
44     # REMOVE THIS LINE IF YOU WANT TO CUSTOMIZE ANYTHING BELOW
45
46 That's right all you need is the above comment in this file. Jenkins will
47 automatically regenerate this file when your patch is merged so we do not need
48 to do anything special here.
49
50 Next we will create <new-project>.cfg as follows:
51
52 .. code-block:: yaml
53
54     STREAMS:
55         - boron:
56             branch: master
57             jdks: openjdk8
58     DEPENDENCIES: odlparent,controller,yangtools
59
60 This is the minimal required CFG file contents and is used to auto-generate the
61 YAML file. If you'd like to explore the additional tweaking options available
62 please refer to the `Tuning Templates`_ section.
63
64 Finally we need to push these files to Gerrit for review by the releng/builder
65 team to push your jobs to Jenkins.
66
67 .. code-block:: bash
68
69     git add jjb/<new-project>
70     git commit -sm "Add <new-project> jobs to Jenkins"
71     git review
72
73 This will push the jobs to Gerrit and your jobs will appear in Jenkins once the
74 releng/builder team has reviewed and merged your patch.
75
76 Jenkins Master
77 --------------
78
79 The `jenkins-master`_ is the home for all project's Jenkins jobs. All
80 maintenance and configuration of these jobs must be done via JJB through the
81 `releng-builder-repo`_. Project contributors can no longer edit the Jenkins jobs
82 directly on the server.
83
84 Build Minions
85 -------------
86
87 The Jenkins jobs are run on build minions (executors) which are created on an
88 as-needed basis. If no idle build minions are available a new VM is brought
89 up. This process can take up to 2 minutes. Once the build minion has finished a
90 job, it will remain online for 45 minutes before shutting down. Subsequent
91 jobs will use an idle build minion if available.
92
93 Our Jenkins master supports many types of dynamic build minions. If you are
94 creating custom jobs then you will need to have an idea of what type of minions
95 are available. The following are the current minion types and descriptions.
96 Minion Template Names are needed for jobs that take advantage of multiple
97 minions as they must be specifically called out by template name instead of
98 label.
99
100 Adding New Components to the Minions
101 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
102
103 If your project needs something added to one of the minions used during build
104 and test you can help us get things added faster by doing one of the following:
105
106 * Submit a patch to RelEng/Builder for the `spinup-scripts`_ that
107   configures your new piece of software.
108 * Submit a patch to RelEng/Builder for the Vagrant template's bootstrap.sh in
109   the `vagrant-definitions`_ directory that configures your new piece of
110   software.
111
112 Going the first route will be faster in the short term as we can inspect the
113 changes and make test modifications in the sandbox to verify that it works.
114
115 The second route, however, is better for the community as a whole as it will
116 allow others that utilize our Vagrant setups to replicate our systems more
117 closely. It is, however, more time consuming as an image snapshot needs to be
118 created based on the updated Vagrant definition before it can be attached to
119 the sandbox for validation testing.
120
121 In either case, the changes must be validated in the sandbox with tests to
122 make sure that we don't break current jobs and that the new software features
123 are operating as intended. Once this is done the changes will be merged and
124 the updates applied to the RelEng Jenkins production silo.
125
126 Please note that the combination of a Vagrant minion snapshot and a Jenkins
127 spinup script is what defines a given minion. For instance, a minion may be
128 defined by the `vagrant-basic-java-node`_ Vagrant definition
129 and the `spinup-scripts-controller.sh`_ Jenkins spinup script
130 (as the dynamic\_controller minion is). The pair provides the full definition of
131 the realized minion. Jenkins starts a minion using the last-spun Vagrant snapshot
132 for the specified definition. Once the base Vagrant instance is online Jenkins
133 checks out the RelEng/Builder repo on it and executes two scripts. The first is
134 `spinup-scripts-basic_settings.sh`_, which is a baseline for all of the minions.
135 The second is
136 the specialized spinup script, which handles any system updates, new software
137 installs or extra environment tweaks that don't make sense in a snapshot. After
138 all of these scripts have executed Jenkins will finally attach the minion as an
139 actual minion and start handling jobs on it.
140
141 Pool: ODLRPC
142 ^^^^^^^^^^^^^^^^^^^
143
144 .. raw:: html
145
146     <table class="table table-bordered">
147       <tr class="warning">
148         <td><b>Jenkins Label</b><br/> dynamic_verify</td>
149         <td><b>Minion Template name</b><br/> centos7-builder</td>
150         <td><b>Vagrant Definition</b><br/> releng/builder/vagrant/basic-builder</td>
151         <td><b>Spinup Script</b><br/> releng/builder/jenkins-scripts/builder.sh</td>
152       </tr>
153       <tr>
154         <td colspan="4">
155           A CentOS 7 huild minion. This system has OpenJDK 1.7 (Java7) and OpenJDK
156           1.8 (Java8) installed on it along with all the other components and
157           libraries needed for building any current OpenDaylight project. This is
158           the label that is used for all basic -verify and -daily- builds for
159           projects.
160         </td>
161       </tr>
162
163       <tr class="warning">
164         <td><b>Jenkins Label</b><br/> dynamic_merge</td>
165         <td><b>Minion Template name</b><br/> centos7-builder</td>
166         <td><b>Vagrant Definition</b><br/> releng/builder/vagrant/basic-builder</td>
167         <td><b>Spinup Script</b><br/> releng/builder/jenkins-scripts/builder.sh</td>
168       </tr>
169       <tr>
170         <td colspan="4">
171           See dynamic_verify (same image on the back side). This is the label that
172           is used for all basic -merge and -integration- builds for projects.
173         </td>
174       </tr>
175
176       <tr class="warning">
177         <td><b>Jenkins Label</b><br/> matrix_master</td>
178         <td><b>Minion Template name</b><br/> centos7-matrix</td>
179         <td><b>Vagrant Definition</b><br/> releng/builder/vagrant/basic-java-node</td>
180         <td><b>Spinup Script</b><br/> releng/builder/jenkins-scripts/matrix.sh</td>
181       </tr>
182       <tr>
183         <td colspan="4">
184           This is a very minimal system that is designed to spin up with 2 build
185           instances on it. The purpose is to have a location that is not the
186           Jenkins master itself for jobs that are executing matrix operations
187           since they need a director location. This image should not be used for
188           anything but tying matrix jobs before the matrx defined label ties.
189         </td>
190       </tr>
191
192       <tr class="warning">
193         <td><b>Jenkins Label</b><br/> dynamic_robot</td>
194         <td><b>Minion Template name</b><br/> centos7-robot</td>
195         <td><b>Vagrant Definition</b><br/> releng/builder/vagrant/integration-robotframework</td>
196         <td><b>Spinup Script</b><br/> releng/builder/jenkins-scripts/robot.sh</td>
197       </tr>
198       <tr>
199         <td colspan="4">
200           A CentOS 7 minion that is configured with OpenJDK 1.7 (Java7), OpenJDK
201           1.8 (Java8) and all the current packages used by the integration
202           project for doing robot driven jobs. If you are executing robot
203           framework jobs then your job should be using this as the minion that
204           you are tied to. This image does not contain the needed libraries for
205           building components of OpenDaylight, only for executing robot tests.
206         </td>
207       </tr>
208
209       <tr class="warning">
210         <td><b>Jenkins Label</b><br/> ubuntu_mininet</td>
211         <td><b>Minion Template name</b><br/> ubuntu-trusty-mininet</td>
212         <td><b>Vagrant Definition</b><br/> releng/builder/vagrant/ubuntu-mininet</td>
213         <td><b>Spinup Script</b><br/> releng/builder/jenkins-scripts/mininet-ubuntu.sh</td>
214       </tr>
215       <tr>
216         <td colspan="4">
217           Basic Ubuntu system with ovs 2.0.2 and mininet 2.1.0
218         </td>
219       </tr>
220
221       <tr class="warning">
222         <td><b>Jenkins Label</b><br/> ubuntu_mininet_ovs_23</td>
223         <td><b>Minion Template name</b><br/> ubuntu-trusty-mininet-ovs-23</td>
224         <td><b>Vagrant Definition</b><br/> releng/builder/vagrant/ubuntu-mininet-ovs-23</td>
225         <td><b>Spinup Script</b><br/> releng/builder/jenkins-scripts/mininet-ubuntu.sh</td>
226       </tr>
227       <tr>
228         <td colspan="4">
229           Basic Ubuntu system with ovs 2.3 and mininet 2.2.1
230         </td>
231       </tr>
232
233       <tr class="warning">
234         <td><b>Jenkins Label</b><br/> dynamic_controller</td>
235         <td><b>Minion Template name</b><br/> centos7-java</td>
236         <td><b>Vagrant Definition</b><br/> releng/builder/vagrant/basic-java-node</td>
237         <td><b>Spinup Script</b><br/> releng/builder/jenkins-scripts/controller.sh</td>
238       </tr>
239       <tr>
240         <td colspan="4">
241           A CentOS 7 minion that has the basic OpenJDK 1.7 (Java7) and OpenJDK
242           1.8 (Java8) installed and is capable of running the controller, not
243           building.
244         </td>
245       </tr>
246
247       <tr class="warning">
248         <td><b>Jenkins Label</b><br/> dynamic_java</td>
249         <td><b>Minion Template name</b><br/> centos7-java</td>
250         <td><b>Vagrant Definition</b><br/> releng/builder/vagrant/basic-java-node</td>
251         <td><b>Spinup Script</b><br/> releng/builder/jenkins-scripts/controller.sh</td>
252       </tr>
253       <tr>
254         <td colspan="4">
255           See dynamic_controller as it is currently the same image.
256         </td>
257       </tr>
258
259       <tr class="warning">
260         <td><b>Jenkins Label</b><br/> dynamic_java_8g</td>
261         <td><b>Minion Template name</b><br/> centos7-java-8g</td>
262         <td><b>Vagrant Definition</b><br/> releng/builder/vagrant/basic-java-node</td>
263         <td><b>Spinup Script</b><br/> releng/builder/jenkins-scripts/controller.sh</td>
264       </tr>
265       <tr>
266         <td colspan="4">
267           See dynamic_controller as it is currently the same image but with 8G of RAM.
268         </td>
269       </tr>
270
271       <tr class="warning">
272         <td><b>Jenkins Label</b><br/> dynamic_devstack</td>
273         <td><b>Minion Template name</b><br/> centos7-devstack</td>
274         <td><b>Vagrant Definition</b><br/> releng/builder/vagrant/ovsdb-devstack</td>
275         <td><b>Spinup Script</b><br/> releng/builder/jenkins-scripts/devstack.sh</td>
276       </tr>
277       <tr>
278         <td colspan="4">
279           A CentOS 7 system purpose built for doing OpenStack testing using
280           DevStack. This minion is primarily targeted at the needs of the OVSDB
281           project. It has OpenJDK 1.7 (aka Java7) and OpenJDK 1.8 (Java8) and
282           other basic DevStack related bits installed.
283         </td>
284       </tr>
285
286       <tr class="warning">
287         <td><b>Jenkins Label</b><br/> dynamic_docker</td>
288         <td><b>Minion Template name</b><br/> centos7-docker</td>
289         <td><b>Vagrant Definition</b><br/> releng/builder/vagrant/ovsdb-docker</td>
290         <td><b>Spinup Script</b><br/> releng/builder/jenkins-scripts/docker.sh</td>
291       </tr>
292       <tr>
293         <td colspan="4">
294           A CentOS 7 system that is configured with OpenJDK 1.7 (aka Java7),
295           OpenJDK 1.8 (Java8) and Docker. This system was originally custom
296           built for the test needs of the OVSDB project but other projects have
297           expressed interest in using it.
298         </td>
299       </tr>
300
301       <tr class="warning">
302         <td><b>Jenkins Label</b><br/> gbp_trusty</td>
303         <td><b>Minion Template name</b><br/> gbp_trusty</td>
304         <td><b>Vagrant Definition</b><br/> releng/builder/vagrant/gbp-ubuntu-docker-ovs-node</td>
305         <td><b>Spinup Script</b><br/> releng/builder/jenkins-scripts/ubuntu-docker-ovs.sh</td>
306       </tr>
307       <tr>
308         <td colspan="4">
309           A basic Ubuntu node with latest OVS and docker installed. Used by Group Based Policy.
310         </td>
311       </tr>
312     </table>
313
314 Creating Jenkins Jobs
315 ---------------------
316
317 Jenkins Job Builder takes simple descriptions of Jenkins jobs in YAML format
318 and uses them to configure Jenkins.
319
320 * `Jenkins Job Builder (JJB) documentation <jjb-docs_>`_
321 * `RelEng/Builder Gerrit <releng-builder-gerrit_>`_
322 * `RelEng/Builder Git repository <releng-builder-repo_>`_
323
324 Getting Jenkins Job Builder
325 ---------------------------
326
327 OpenDaylight uses Jenkins Job Builder to translate our in-repo YAML job
328 configuration into job descriptions suitable for consumption by Jenkins.
329 When testing new Jenkins Jobs in the `Jenkins Sandbox`_, you'll
330 need to use the `jenkins-jobs` executable to translate a set of jobs into
331 their XML descriptions and upload them to the sandbox Jenkins server.
332
333 We document `installing <Installing Jenkins Job Builder_>`_ `jenkins-jobs`
334 below. We also provide
335 a `pre-built Docker image <jjb-docker_>`_ with `jenkins-jobs` already installed.
336
337 Installing Jenkins Job Builder
338 ------------------------------
339
340 For users who aren't already experienced with Docker or otherwise don't want
341 to use our `pre-built JJB Docker image <jjb-docker_>`_, installing JJB into a
342 virtual environment is an equally good option.
343
344 We recommend using `pip <Installing JJB using pip_>`_ to assist with JJB
345 installs, but we
346 also document `installing from a git repository manually
347 <Installing JJB Manually_>`_.
348 For both, we recommend using Python `Virtual Environments`_
349 to isolate JJB and its dependencies.
350
351 The `builder/jjb/requirements.txt <odl-jjb-requirements.txt_>`_ file contains the currently
352 recommended JJB version. Because JJB is fairly unstable, it may be necessary
353 to debug things by installing different versions. This is documented for both
354 `pip-assisted <Installing JJB using pip_>`_ and `manual
355 <Installing JJB Manually_>`_ installs.
356
357 Virtual Environments
358 --------------------
359
360 For both `pip-assisted <Installing JJB using pip_>`_ and `manual
361 <Installing JJB Manually_>`_ JJB
362 installs, we recommend using `Python Virtual Environments <python-virtualenv_>`_
363 to manage JJB and its
364 Python dependencies. The `python-virtualenvwrapper`_ tool can help you do so.
365
366 There are good docs for installing `python-virtualenvwrapper`_. On Linux systems
367 with pip (typical), they amount to:
368
369 .. code-block:: bash
370
371     sudo pip install virtualenvwrapper
372
373 A virtual environment is simply a directory that you install Python programs
374 into and then append to the front of your path, causing those copies to be
375 found before any system-wide versions.
376
377 Create a new virtual environment for JJB.
378
379 .. code-block:: bash
380
381     # Virtaulenvwrapper uses this dir for virtual environments
382     $ echo $WORKON_HOME
383     /home/daniel/.virtualenvs
384     # Make a new virtual environment
385     $ mkvirtualenv jjb
386     # A new venv dir was created
387     (jjb)$ ls -rc $WORKON_HOME | tail -n 1
388     jjb
389     # The new venv was added to the front of this shell's path
390     (jjb)$ echo $PATH
391     /home/daniel/.virtualenvs/jjb/bin:<my normal path>
392     # Software installed to venv, like pip, is found before system-wide copies
393     (jjb)$ command -v pip
394     /home/daniel/.virtualenvs/jjb/bin/pip
395
396 With your virtual environment active, you should install JJB. Your install will
397 be isolated to that virtual environment's directory and only visible when the
398 virtual environment is active.
399
400 You can easily leave and return to your venv. Make sure you activate it before
401 each use of JJB.
402
403 .. code-block:: bash
404
405     (jjb)$ deactivate
406     $ command -v jenkins-jobs
407     # No jenkins-jobs executable found
408     $ workon jjb
409     (jjb)$ command -v jenkins-jobs
410     $WORKON_HOME/jjb/bin/jenkins-jobs
411
412 Installing JJB using pip
413 ------------------------
414
415 The recommended way to install JJB is via pip.
416
417 First, clone the latest version of the `releng-builder-repo`_.
418
419 .. code-block:: bash
420
421     $ git clone https://git.opendaylight.org/gerrit/p/releng/builder.git
422
423 Before actually installing JJB and its dependencies, make sure you've `created
424 and activated <Virtual Environments_>`_ a virtual environment for JJB.
425
426 .. code-block:: bash
427
428     $ mkvirtualenv jjb
429
430 The recommended version of JJB to install is the version specified in the
431 `builder/jjb/requirements.txt <odl-jjb-requirements.txt_>`_ file.
432
433 .. code-block:: bash
434
435     # From the root of the releng/builder repo
436     (jjb)$ pip install -r jjb/requirements.txt
437
438 To validate that JJB was successfully installed you can run this command:
439
440 .. code-block:: bash
441
442     (jjb)$ jenkins-jobs --version
443
444 To change the version of JJB specified by `builder/jjb/requirements.txt
445 <odl-jjb-requirements.txt_>`_
446 to install from the latest commit to the master branch of JJB's git repository:
447
448 .. code-block:: bash
449
450     $ cat jjb/requirements.txt
451     -e git+https://git.openstack.org/openstack-infra/jenkins-job-builder#egg=jenkins-job-builder
452
453 To install from a tag, like 1.4.0:
454
455 .. code-block:: bash
456
457     $ cat jjb/requirements.txt
458     -e git+https://git.openstack.org/openstack-infra/jenkins-job-builder@1.4.0#egg=jenkins-job-builder
459
460 Installing JJB Manually
461 -----------------------
462
463 This section documents installing JJB from its manually cloned repository.
464
465 Note that `installing via pip <Installing JJB using pip_>`_ is typically simpler.
466
467 Checkout the version of JJB's source you'd like to build.
468
469 For example, using master:
470
471 .. code-block:: bash
472
473     $ git clone https://git.openstack.org/openstack-infra/jenkins-job-builder
474
475 Using a tag, like 1.4.0:
476
477 .. code-block:: bash
478
479     $ git clone https://git.openstack.org/openstack-infra/jenkins-job-builder
480     $ cd jenkins-job-builder
481     $ git checkout tags/1.4.0
482
483 Before actually installing JJB and its dependencies, make sure you've `created
484 and activated <Virtual Environments_>`_ a virtual environment for JJB.
485
486 .. code-block:: bash
487
488     $ mkvirtualenv jjb
489
490 You can then use JJB's `requirements.txt <jjb-requirements.txt_>`_ file to
491 install its
492 dependencies. Note that we're not using `sudo` to install as root, since we want
493 to make use of the venv we've configured for our current user.
494
495 .. code-block:: bash
496
497     # In the cloned JJB repo, with the desired version of the code checked out
498     (jjb)$ pip install -r requirements.txt
499
500 Then install JJB from the repo with:
501
502 .. code-block:: bash
503
504     (jjb)$ pip install .
505
506 To validate that JJB was successfully installed you can run this command:
507
508 .. code-block:: bash
509
510     (jjb)$ jenkins-jobs --version
511
512 JJB Docker Image
513 ----------------
514
515 `Docker <docker-docs_>`_ is an open platform used to create virtualized Linux containers
516 for shipping self-contained applications. Docker leverages LinuX Containers
517 \(LXC\) running on the same operating system as the host machine, whereas a
518 traditional VM runs an operating system over the host.
519
520 .. code-block:: bash
521
522     docker pull zxiiro/jjb-docker
523     docker run --rm -v ${PWD}:/jjb jjb-docker
524
525 This `Dockerfile <jjb-dockerfile_>`_ created the
526 `zxiiro/jjb-docker image <jjb-docker_>`_.
527 By default it will run:
528
529 .. code-block:: bash
530
531     jenkins-jobs test .
532
533 You'll need to use the `-v/--volume=[]` parameter to mount a directory
534 containing your YAML files, as well as a configured `jenkins.ini` file if you
535 wish to upload your jobs to the `Jenkins Sandbox`_.
536
537 Jenkins Job Templates
538 ---------------------
539
540 The OpenDaylight `RelEng/Builder <releng-builder-wiki_>`_ project provides
541 `jjb-templates`_ that can be used to define basic jobs.
542
543 The *Gerrit Trigger* listed in the jobs are keywords that can be used to
544 trigger the job to run manually by simply leaving a comment in Gerrit for the
545 patch you wish to trigger against.
546
547 All jobs have a default build-timeout value of 360 minutes (6 hrs) but can be
548 overrided via the opendaylight-infra-wrappers' build-timeout property.
549
550 .. raw:: html
551
552     <table class="table table-bordered">
553       <tr class="warning">
554         <td><b>Job Template</b><br/>{project}-distribution-{stream}</td>
555         <td><b>Gerrit Trigger</b><br/>test-distribution</td>
556       </tr>
557       <tr>
558         <td colspan="2">
559           This job builds a distrbution against your patch, passes distribution sanity test
560           and reports back the results to Gerrit. Leave a comment with trigger keyword above
561           to activate it for a particular patch.
562
563           This job is maintained by the <a href="https://wiki.opendaylight.org/view/Integration/Test">Integration/Test</a>
564           project.
565
566           <div class="admonition note">
567             <p class="first admonition-title">Note</p>
568             <p>
569               Running the "test-distribution" trigger will cause Jenkins to
570               remove it's existing vote if it's already -1 or +1'd a comment.
571               You will need to re-run your verify job (recheck) after running
572               this to get Jenkins to put back the correct vote.
573             </p>
574           </div>
575         </td>
576       </tr>
577
578       <tr class="warning">
579         <td><b>Job Template</b><br/>{project}-integration-{stream}</td>
580         <td></td>
581       </tr>
582       <tr>
583         <td colspan="2">
584           The Integration Job Template creates a job which runs when a project that your
585           project depends on is successfully built. This job type is basically the same
586           as a verify job except that it triggers from other Jenkins jobs instead of via
587           Gerrit review updates. The dependencies that triger integration jobs are listed
588           in your project.cfg file under the <b>DEPENDENCIES</b> variable.
589
590           If no dependencies are listed then this job type is disabled by default.
591         </td>
592       </tr>
593
594       <tr class="warning">
595         <td><b>Job Template</b><br/>{project}-merge-{stream}</td>
596         <td><b>Gerrit Trigger</b><br/>remerge</td>
597       </tr>
598       <tr>
599         <td colspan="2">
600           The Merge job template is similar to the Verify Job Template except
601           it will trigger once a Gerrit patch is merged into the repo. It
602           also automatically runs the Maven goals <b>source:jar</b> and
603           <b>javadoc:jar</b>.
604
605           This job will upload artifacts to OpenDaylight's
606           <a href="https://nexus.opendaylight.org">Nexus</a> on completion.
607         </td>
608       </tr>
609
610       <tr class="warning">
611         <td><b>Job Template</b><br/>{project}-sonar</td>
612         <td><b>Gerrit Trigger</b><br/>run-sonar</td>
613       </tr>
614       <tr>
615         <td colspan="2">
616           This job runs Sonar analysis and reports the results to
617           OpenDaylight's <a href="https://sonar.opendaylight.org">Sonar</a>
618           dashboard.
619
620           The Sonar Job Template creates a job which will run against the
621           master branch, or if BRANCHES are specified in the CFG file it will
622           create a job for the <b>First</b> branch listed.
623
624           <div class="admonition note">
625             <p class="first admonition-title">Note</p>
626             <p>
627               Running the "run-sonar" trigger will cause Jenkins to remove
628               its existing vote if it's already -1'd or +1'd a comment. You
629               will need to re-run your verify job (recheck) after running
630               this to get Jenkins to re-vote.
631             </p>
632           </div>
633         </td>
634       </tr>
635
636       <tr class="warning">
637         <td><b>Job Template</b><br/>{project}-validate-autorelease-{stream}</td>
638         <td><b>Gerrit Trigger</b><br/>recheck | reverify</td>
639       </tr>
640       <tr>
641         <td colspan="2">
642           This job runs the PROJECT-validate-autorelease-BRANCH job which is
643           used as a quick sanity test to ensure that a patch does not depend on
644           features that do not exist in the current release.
645
646           The <b>revalidate</b> trigger is useful in cases where a project's
647           verify job passed however validate failed due to infra problems or
648           intermittent issues. It will retrigger just the validate-autorelease
649           job.
650         </td>
651       </tr>
652
653       <tr class="warning">
654         <td><b>Job Template</b><br/>{project}-verify-{stream}</td>
655         <td><b>Gerrit Trigger</b><br/>recheck | reverify</td>
656       </tr>
657       <tr>
658         <td colspan="2">
659             The Verify job template creates a Gerrit Trigger job that will
660             trigger when a new patch is submitted to Gerrit.
661         </td>
662       </tr>
663
664       <tr class="warning">
665         <td><b>Job Template</b><br/>{project}-verify-node-{stream}</td>
666         <td><b>Gerrit Trigger</b><br/>recheck | reverify</td>
667       </tr>
668       <tr>
669         <td colspan="2">
670           This job template can be used by a project that is NodeJS based. It
671           simply installs a python virtualenv and uses that to install nodeenv
672           which is then used to install another virtualenv for nodejs. It then
673           calls <b>npm install</b> and <b>npm test</b> to run the unit tests.
674           When  using this template you need to provide a {nodedir} and
675           {nodever} containing the directory relative to the project root
676           containing the nodejs package.json and version of node you wish to
677           run tests with.
678         </td>
679       </tr>
680
681       <tr class="warning">
682         <td><b>Job Template</b><br/>{project}-verify-python-{stream}</td>
683         <td><b>Gerrit Trigger</b><br/>recheck | reverify</td>
684       </tr>
685       <tr>
686         <td colspan="2">
687           This job template can be used by a project that is Python based. It
688           simply installs a python virtualenv and uses tox to run tests. When
689           using the template you need to provide a {toxdir} which is the path
690           relative to the root of the project repo containing the tox.ini file.
691         </td>
692       </tr>
693
694       <tr class="warning">
695         <td><b>Job Template</b><br/>integration-patch-test-{stream}</td>
696         <td><b>Gerrit Trigger</b><br/>test-integration</td>
697       </tr>
698       <tr>
699         <td colspan="2">
700           This job runs a full integration test suite against your patch and
701           reports back the results to Gerrit. Leave a comment with trigger
702           keyword above to activate it for a particular patch.
703
704           It then spawns the list of jobs in csit-list defined
705           <a href="https://git.opendaylight.org/gerrit/gitweb?p=releng/builder.git;a=blob;f=jjb/integration/integration-test-jobs.yaml">here</a>.
706
707           This job is maintained by the <a href="https://wiki.opendaylight.org/view/Integration/Test">Integration/Test</a>
708           project.
709
710           <div class="admonition note">
711             <p class="first admonition-title">Note</p>
712             <p>
713               Running the "test-integration" trigger will cause Jenkins to remove
714               it's existing vote if it's already -1 or +1'd a comment. You will need
715               to re-run your verify job (recheck) after running this to get Jenkins
716               to put back the correct vote.
717             </p>
718           </div>
719
720           Some considerations when using this job:
721           <ul>
722             <li>
723               The patch test verification takes some time (~2 hours) + consumes a lot of
724               resources so it is not meant to be used for every patch.
725             </li>
726             <li>
727               The system tests for master patches will fail most of the times because both
728               code and test are unstable during the release cycle (should be good by the
729               end of the cycle).
730             </li>
731             <li>
732               Because of the above, patch test results typically have to be interpreted by
733               system test experts. The <a href="https://wiki.opendaylight.org/view/Integration/Test">Integration/Test</a>
734               project can help with that.
735             </li>
736         </td>
737       </tr>
738     </table>
739
740 Basic Job Configuration
741 -----------------------
742
743 To create jobs based on existing `templates <Jenkins Job Templates_>`_, use the
744 `jjb-init-project.py`_ helper script. When run from the root of
745 `RelEng/Builder's repo <releng-builder-repo_>`_, it will produce a file in
746 `jjb/<project>/<project>.yaml` containing your project's base template.
747
748 .. code-block:: bash
749
750     $ python scripts/jjb-init-project.py --help
751     usage: jjb-init-project.py [-h] [-c CONF] [-d DEPENDENCIES] [-t TEMPLATES]
752                                [-s STREAMS] [-p POM] [-g MVN_GOALS] [-o MVN_OPTS]
753                                [-a ARCHIVE_ARTIFACTS]
754                                project
755
756     positional arguments:
757       project               project
758
759     optional arguments:
760       -h, --help            show this help message and exit
761       -c CONF, --conf CONF  Config file
762       -d DEPENDENCIES, --dependencies DEPENDENCIES
763                             Project dependencies A comma-seperated (no spaces)
764                             list of projects your project depends on. This is used
765                             to create an integration job that will trigger when a
766                             dependent project-merge job is built successfully.
767                             Example: aaa,controller,yangtools
768       -t TEMPLATES, --templates TEMPLATES
769                             Job templates to use
770       -s STREAMS, --streams STREAMS
771                             Release streams to fill with default options
772       -p POM, --pom POM     Path to pom.xml to use in Maven build (Default:
773                             pom.xml
774       -g MVN_GOALS, --mvn-goals MVN_GOALS
775                             Maven Goals
776       -o MVN_OPTS, --mvn-opts MVN_OPTS
777                             Maven Options
778       -a ARCHIVE_ARTIFACTS, --archive-artifacts ARCHIVE_ARTIFACTS
779                             Comma-seperated list of patterns of artifacts to
780                             archive on build completion. See:
781                             http://ant.apache.org/manual/Types/fileset.html
782
783 If all your project requires is the basic verify, merge, and daily jobs then
784 using the job template should be all you need to configure for your jobs.
785
786 Auto-Update Job Templates
787 ^^^^^^^^^^^^^^^^^^^^^^^^^
788
789 The first line of the job YAML file produced by the `jjb-init-project.py`_ script will
790 contain the words `# REMOVE THIS LINE IF...`. Leaving this line will allow the
791 RelEng/Builder `jjb-autoupdate-project.py`_ script to maintain this file for your project,
792 should the base templates ever change. It is a good idea to leave this line if
793 you do not plan to create any complex jobs outside of the provided template.
794
795 However, if your project needs more control over your jobs or if you have any
796 additional configuration outside of the standard configuration provided by the
797 template, then this line should be removed.
798
799 Tuning Templates
800 """"""""""""""""
801
802 Allowing the auto-updated to manage your templates doesn't prevent you from
803 doing some configuration changes. Parameters can be passed to templates via
804 a `<project>.cfg` in your `builder/jjb/<project>` directory. An example is
805 provided below, others can be found in the repos of other projects. Tune as
806 necessary. Unnecessary paramaters can be removed or commented out with a "#"
807 sign.
808
809 .. code-block:: yaml
810
811     JOB_TEMPLATES: verify,merge,sonar
812     STREAMS:
813     - beryllium:
814         branch: master
815         jdks: openjdk7,openjdk8
816         autorelease: true
817     - stable-lithium:
818         branch: stable/lithium
819         jdks: openjdk7
820     POM: dfapp/pom.xml
821     MVN_GOALS: clean install javadoc:aggregate -DrepoBuild -Dmaven.repo.local=$WORKSPACE/.m2repo -Dorg.ops4j.pax.url.mvn.localRepository=$WORKSPACE/.m2repo
822     MVN_OPTS: -Xmx1024m -XX:MaxPermSize=256m
823     DEPENDENCIES: aaa,controller,yangtools
824     ARCHIVE_ARTIFACTS: "*.logs, *.patches"
825
826 .. note:: `STREAMS <streams-design-background_>`_ is a list of branches you want
827           JJB to generate jobs for.
828           The first branch will be the branch that reports Sonar analysis. Each
829           branch must define a "jdks:" section listing the JDKs the verify jobs
830           should run tests against for the branch. The first JDK listed will be
831           used as the default JDK for non-verify type jobs.
832
833 .. note:: Projects that are participating in the simultanious release should set
834           "autorelease: true" under the streams they are participating in
835           autorelease for. This enables a new job type validate-autorelease
836           which is used to help identify if Gerrit patches might break
837           autorelease or not.
838
839 Advanced
840 """"""""
841
842 It is also possible to take advantage of both the auto-updater and creating
843 your own jobs. To do this, create a YAML file in your project's sub-directory
844 with any name other than \<project\>.yaml. The auto-update script will only
845 search for files with the name \<project\>.yaml. The normal \<project\>.yaml
846 file can then be left in tact with the "# REMOVE THIS LINE IF..." comment so
847 it will be automatically updated.
848
849 Maven Properties
850 ----------------
851
852 We provide a properties which your job can take advantage of if you want to do
853 something different depending on the job type that is run. If you create a
854 profile that activates on a property listed blow. The JJB templated jobs will
855 be able to activate the profile during the build to run any custom code you
856 wish to run in your project.
857
858 .. code-block:: bash
859
860     -Dmerge   : This flag is passed in our Merge job and is equivalent to the
861                 Maven property
862                 <merge>true</merge>.
863     -Dsonar   : This flag is passed in our Sonar job and is equivalent to the
864                 Maven property
865                 <sonar>true</sonar>.
866
867 Jenkins Sandbox
868 ---------------
869
870 The `jenkins-sandbox`_ instance's purpose is to allow projects to test their JJB
871 setups before merging their code over to the RelEng master silo. It is
872 configured similarly to the master instance, although it cannot publish
873 artifacts or vote in Gerrit.
874
875 If your project requires access to the sandbox please open an OpenDaylight
876 Helpdesk ticket (<helpdesk@opendaylight.org>) and provide your ODL ID.
877
878 Notes Regarding the Sandbox
879 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
880
881 * Jobs are automatically deleted every Saturday at 08:00 UTC
882 * Committers can login and configure Jenkins jobs in the sandbox directly
883   (unlike with the master silo)
884 * Sandbox configuration mirrors the master silo when possible
885 * Sandbox jobs can NOT upload artifacts to Nexus
886 * Sandbox jobs can NOT vote on Gerrit
887
888 Configuration
889 ^^^^^^^^^^^^^
890
891 Make sure you have Jenkins Job Builder [properly installed](#jjb_install).
892
893 If you do not already have access, open an OpenDaylight Helpdesk ticket
894 (<helpdesk@opendaylight.org>) to request access to ODL's sandbox instance.
895 Integration/Test (`integration-test-wiki`_) committers have access by default.
896
897 JJB reads user-specific configuration from a `jenkins.ini`_. An
898 example is provided by releng/builder at `example-jenkins.ini`_.
899
900 .. code-block:: bash
901
902     # If you don't have RelEng/Builder's repo, clone it
903     $ git clone https://git.opendaylight.org/gerrit/p/releng/builder.git
904     # Make a copy of the example JJB config file (in the builder/ directory)
905     $ cp jenkins.ini.example jenkins.ini
906     # Edit jenkins.ini with your username, API token and ODL's sandbox URL
907     $ cat jenkins.ini
908     <snip>
909     [jenkins]
910     user=<your ODL username>
911     password=<your ODL Jenkins sandbox API token>
912     url=https://jenkins.opendaylight.org/sandbox
913     <snip>
914
915 To get your API token, `login to the Jenkins **sandbox** instance
916 <jenkins-sandbox-login_>`_ (*not
917 the main master Jenkins instance, different tokens*), go to your user page (by
918 clicking on your username, for example), click "Configure" and then "Show API
919 Token".
920
921 Manual Method
922 ^^^^^^^^^^^^^
923
924 If you `installed JJB locally into a virtual environment
925 <Installing Jenkins Job Builder_>`_,
926 you should now activate that virtual environment to access the `jenkins-jobs`
927 executable.
928
929 .. code-block:: bash
930
931     $ workon jjb
932     (jjb)$
933
934 You'll want to work from the root of the RelEng/Builder repo, and you should
935 have your `jenkins.ini` file [properly configured](#sandbox_config).
936
937 Testing Jobs
938 ^^^^^^^^^^^^
939
940 It's good practice to use the `test` command to validate your JJB files before
941 pushing them.
942
943 .. code-block:: bash
944
945     jenkins-jobs --conf jenkins.ini test jjb/ <job-name>
946
947 If the job you'd like to test is a template with variables in its name, it
948 must be manually expanded before use. For example, the commonly used template
949 `{project}-csit-verify-1node-{functionality}` might expand to
950 `ovsdb-csit-verify-1node-netvirt`.
951
952 .. code-block:: bash
953
954     jenkins-jobs --conf jenkins.ini test jjb/ ovsdb-csit-verify-1node-netvirt
955
956 Successful tests output the XML description of the Jenkins job described by
957 the specified JJB job name.
958
959 Pushing Jobs
960 ^^^^^^^^^^^^
961
962 Once you've `configured your \`jenkins.ini\` <Configuration_>`_ and `verified your
963 JJB jobs <Testing Jobs_>`_ produce valid XML descriptions of Jenkins jobs you
964 can push them to the Jenkins sandbox.
965
966 .. important::
967
968     When pushing with `jenkins-jobs`, a log message with the number
969     of jobs you're pushing will be issued, typically to stdout.
970     **If the number is greater than 1** (or the number of jobs you
971     passed to the command to push) then you are pushing too many
972     jobs and should **`ctrl+c` to cancel the upload**. Else you will
973     flood the system with jobs.
974
975     .. code-block:: bash
976
977         INFO:jenkins_jobs.builder:Number of jobs generated:  1
978
979     **Failing to provide the final `<job-name>` param will push all
980     jobs!**
981
982     .. code-block:: bash
983
984         # Don't push all jobs by omitting the final param! (ctrl+c to abort)
985         jenkins-jobs --conf jenkins.ini update jjb/ <job-name>
986
987 Running Jobs
988 ^^^^^^^^^^^^
989
990 Once you have your Jenkins job configuration `pushed to the
991 Sandbox <Pushing Jobs_>`_ you can trigger it to run.
992
993 Find your newly-pushed job on the `Sandbox's web UI <jenkins-sandbox_>`_. Click
994 on its name to see the job's details.
995
996 Make sure you're `logged in <jenkins-sandbox-login_>`_ to the Sandbox.
997
998 Click "Build with Parameters" and then "Build".
999
1000 Wait for your job to be scheduled and run. Click on the job number to see
1001 details, including console output.
1002
1003 Make changes to your JJB configuration, re-test, re-push and re-run until
1004 your job is ready.
1005
1006 Docker Method
1007 ^^^^^^^^^^^^^
1008
1009 If `using Docker <JJB Docker image_>`_:
1010
1011 .. code-block:: bash
1012
1013     # To test
1014     docker run --rm -v ${PWD}:/jjb zxiiro/jjb-docker
1015
1016 .. important::
1017
1018     When pushing with `jenkins-jobs`, a log message with
1019     the number of jobs you're pushing will be issued, typically to stdout.
1020     **If the number is greater than 1** (or the number of jobs you passed to
1021     the command to push) then you are pushing too many jobs and should **`ctrl+c`
1022     to cancel the upload**. Else you will flood the system with jobs.
1023
1024     .. code-block:: bash
1025
1026           INFO:jenkins_jobs.builder:Number of jobs generated:  1
1027
1028     **Failing to provide the final `<job-name>` param will push all jobs!**
1029
1030     .. code-block:: bash
1031
1032         # To upload jobs to the sandbox
1033         # Please ensure that you include a configured jenkins.ini in your volume mount
1034         # Making sure not to push more jobs than expected, ctrl+c to abort
1035         docker run --rm -v ${PWD}:/jjb zxiiro/jjb-docker jenkins-jobs --conf jenkins.ini update . openflowplugin-csit-periodic-1node-cds-longevity-only-master
1036
1037 .. _docker-docs: https://www.docker.com/whatisdocker/
1038 .. _example-jenkins.ini: https://git.opendaylight.org/gerrit/gitweb?p=releng/builder.git;a=blob;f=jenkins.ini.example
1039 .. _integration-test-wiki: https://wiki.opendaylight.org/view/Integration/Test
1040 .. _jenkins-master: https://jenkins.opendaylight.org/releng
1041 .. _jenkins-sandbox: https://jenkins.opendaylight.org/sandbox
1042 .. _jenkins-sandbox-login: https://jenkins.opendaylight.org/sandbox/login
1043 .. _jenkins.ini: http://docs.openstack.org/infra/jenkins-job-builder/execution.html#configuration-file
1044 .. _jjb-autoupdate-project.py: https://git.opendaylight.org/gerrit/gitweb?p=releng/builder.git;a=blob;f=scripts/jjb-autoupdate-project.py
1045 .. _jjb-docker: https://hub.docker.com/r/zxiiro/jjb-docker/
1046 .. _jjb-dockerfile: https://github.com/zxiiro/jjb-docker/blob/master/Dockerfile
1047 .. _jjb-docs: http://ci.openstack.org/jenkins-job-builder/
1048 .. _jjb-init-project.py: https://git.opendaylight.org/gerrit/gitweb?p=releng/builder.git;a=blob;f=scripts/jjb-init-project.py
1049 .. _jjb-repo: https://github.com/openstack-infra/jenkins-job-builder
1050 .. _jjb-requirements.txt: https://github.com/openstack-infra/jenkins-job-builder/blob/master/requirements.txt
1051 .. _jjb-templates: https://git.opendaylight.org/gerrit/gitweb?p=releng/builder.git;a=tree;f=jjb
1052 .. _odl-jjb-requirements.txt: https://git.opendaylight.org/gerrit/gitweb?p=releng/builder.git;a=blob;f=jjb/requirements.txt
1053 .. _odl-nexus: https://nexus.opendaylight.org
1054 .. _odl-sonar: https://sonar.opendaylight.org
1055 .. _python-virtualenv: https://virtualenv.readthedocs.org/en/latest/
1056 .. _python-virtualenvwrapper: https://virtualenvwrapper.readthedocs.org/en/latest/
1057 .. _releng-wiki: https://wiki.opendaylight.org/view/RelEng:Main
1058 .. _releng-builder-gerrit: https://git.opendaylight.org/gerrit/#/admin/projects/releng/builder
1059 .. _releng-builder-repo: https://git.opendaylight.org/gerrit/gitweb?p=releng%2Fbuilder.git;a=summary
1060 .. _releng-builder-wiki: https://wiki.opendaylight.org/view/RelEng/Builder
1061 .. _streams-design-background: https://lists.opendaylight.org/pipermail/release/2015-July/003139.html
1062 .. _spinup-scripts: https://git.opendaylight.org/gerrit/gitweb?p=releng/builder.git;a=tree;f=jenkins-scripts
1063 .. _spinup-scripts-basic_settings.sh: https://git.opendaylight.org/gerrit/gitweb?p=releng/builder.git;a=blob;f=jenkins-scripts/basic_settings.sh
1064 .. _spinup-scripts-controller.sh: https://git.opendaylight.org/gerrit/gitweb?p=releng/builder.git;a=blob;f=jenkins-scripts/controller.sh
1065 .. _vagrant-basic-java-node: https://git.opendaylight.org/gerrit/gitweb?p=releng/builder.git;a=tree;f=vagrant/basic-java-node
1066 .. _vagrant-definitions: https://git.opendaylight.org/gerrit/gitweb?p=releng/builder.git;a=tree;f=vagrant