rewrite jjb usage file
[octopus.git] / docs / opnfv-jjb-usage.rst
1 ===========================================
2 How to write and use JJB?
3 ============================================
4
5 What is Jenkins Job Builder
6 ----------------------------
7
8 Jenkins Job Builder(JJB) takes simple descriptions of Jenkins jobs in YAML format, and uses them to configure Jenkins jobs. JJB keeps your job descriptions in human readable format and job template system simplifies the configuration of Jenkins jobs. Upstream documentation is available at http://ci.openstack.org/jenkins-job-builder/.
9
10 How to Write/Use Jenkins Job Builder
11 ------------------------------------
12
13 Job template is widely used in JJBs and makes the configuration of Jenkins jobs simple, if you need to define several jobs which are nearly identical, except perhaps in their names, SCP targets, etc., then you may use a job template to specify the particulars of the job, and then use a project to realize the job with appropriate variable substitution.
14
15 To illustrate how to configure Jenkins jobs by using job template, we can start with a simple example used in our OPNFV releng project octopus directory, which is just used to print "Hello world from Octopus", shown as below::
16
17  -job-template:
18     name: octopus-test
19
20     node: master
21
22     project-type: freestyle
23
24     logrotate:
25         daysToKeep: 30
26         numToKeep: 10
27         artifactDaysToKeep: -1
28         artifactNumToKeep: -1
29
30     builders:
31         - shell: |
32             echo "Hello world from octopus"
33
34 the value "-1" here means keep forever, you can add this job template into the project jobs to run in jenkins::
35
36  - project:
37      name: octopus
38      jobs:
39          - 'octopus-test'
40
41 then this job works!
42
43 Further, if you are a developer who wants to set up a job template to be used in jenkins, we should dive into much more, taking one job template in releng project used for octopus project, the 'octopus-daily-{stream}', as an example::
44
45  -job-template:
46     name: 'octopus-daily-{stream}'
47
48     node: master
49
50     # Job template for daily builders
51     #
52     # Required Variables:
53     #     stream:    branch with - in place of / (eg. stable)
54     #     branch:    branch (eg. stable)
55
56     project-type: freestyle
57     varsetabove: '{somevar}'
58
59     logrotate:
60         daysToKeep: '{build-days-to-keep}'
61         numToKeep: '{build-num-to-keep}'
62         artifactDaysToKeep: '{build-artifact-days-to-keep}'
63         artifactNumToKeep: '{build-artifact-num-to-keep}'
64
65     parameters:
66         - project-parameter:
67             project: '{project}'
68
69     scm:
70         - git-scm:
71             credentials-id: '{ssh-credentials}'
72             refspec: ''
73             branch: '{branch}'
74
75     wrappers:
76         - ssh-agent-credentials:
77             user: '{ssh-credentials}'
78
79     triggers:
80         - timed: 'H H * * *'
81
82     prebuilders:
83         - test-macro
84
85     builders:
86         - shell:
87             !include-raw build-upload-docu.sh
88
89     postbulders:
90         - test-macro
91
92 the {stream} here means when you add this into jobs, you can replace {stream} with what you want, such as::
93
94  stream:
95         - master:
96             branch: 'master'
97
98 the::
99
100  node: master
101
102 means to restrict this job to run in Jenkins master node. Next, several important procedures are illustrated here,
103
104 - scm, this mudule allows you to specify the source code location for the project, and it allows referencing multiple repositories in a Jenkins job.
105 - triggers, this module defines what causes a Jenkins job to start building.
106 - prebuilders and postbuilders, which define job need done pre and post the builders.
107 - builders, which defines actions that the Jenkins job should execute, usually the shell scripts or maven targets are existed there, e.g., build-upload-docu.sh used in our example.
108
109 Generally, the modules used in a job template is sequenced as
110
111 1.parameters, properties
112 2.scm
113 3.triggers
114 4.wrappers
115 5.prebuilders
116 6.builders
117 7.postbuilders
118 8.publishers, reporters, notifications
119
120 Working with OPNFV Jenkins Jobs
121 -------------------------------
122
123 By now, the releng project of OPNFV is the release engineering project for JJBs, you can clone the repo::
124
125  git clone ssh://YOU@gerrit.opnfv.org:29418/releng
126
127 make changes::
128
129  git commit -sv
130  git review
131  remote: Resolving deltas: 100% (3/3)
132  remote: Processing changes: new: 1, refs: 1, done
133  remote:
134  remote: New Changes:
135  remote:   https://gerrit.opnfv.org/gerrit/51
136  remote:
137  To ssh://agardner@gerrit.opnfv.org:29418/releng.git
138   * [new branch]      HEAD -> refs/publish/master
139
140 Follow the link to gerrit https://gerrit.opnfv.org/gerrit/51 in a few moments the verify job will have completed and you will see Verified +1 jenkins-ci in the gerrit ui.
141
142 If the changes pass the verify job https://build.opnfv.org/ci/view/builder/job/builder-verify-jjb/ The patch can be submitited by a committer.
143
144 Job Types
145
146 * Verify Job
147
148  * Trigger: **recheck** or **reverify**
149
150 * Merge Job
151  * Trigger: **remerge**
152
153 The verify and merge jobs are retriggerable in Gerrit by simply leaving a comment with one of the keywords listed above. This is useful in case you need to re-run one of those jobs in case if build issues or something changed with the environment.
154
155 You can add below persons as reviewers to your patch in order to get it reviewed and submitted.
156
157 * Ulrich Kleber (Ulrich.Kleber@huawei.com)
158 * Fatih Degirmenci (fatih.degirmenci@ericsson.com)
159 * Xinyu Zhao(Jerry) (zhaoxinyu@huawei.com)
160 * Aric Gardner (agardner@linuxfoundation.org)
161
162 The Current merge and verify jobs for jenkins job builder for releng project, shown in https://git.opnfv.org/cgit/releng/tree/jjb.
163
164 Assuming that you have set up some job templates and put them into a project, then the question is that how they work? Taking the jobs 'builder-verify-jjb', 'builder-merge' used in releng project as examples, 'builder-verify-jjb' is to verify jobs you commited, you will see verified '+1' jenkins-ci in gerrit if it succeed, 'builder-merge' is to set up a merge job and update all the JJBs. If you have some new jobs need to be run, you can set up your own job templates and add them into the project.
165
166 **Documentation tracking**
167
168 Revision: _sha1_
169
170 Build date:  _date_