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