Merge "Document undocumented Python macros"
[releng/global-jjb.git] / docs / jjb / lf-python-jobs.rst
1 ###########
2 Python Jobs
3 ###########
4
5 Job Groups
6 ==========
7
8 {project-name}-python-jobs
9 --------------------------
10
11 Jobs for Python projects using Gerrit.
12
13 :Includes:
14
15     - gerrit-tox-verify
16
17 {project-name}-github-python-jobs
18 ---------------------------------
19
20 Jobs for Python projects using GitHub.
21
22 :Includes:
23
24     - github-tox-verify
25
26
27 Macros
28 ======
29
30 lf-infra-clm-python
31 -------------------
32
33 Run CLM scanning against a Python project.
34
35 :Required Parameters:
36
37     :clm-project-name: Project name in Nexus IQ to send results to.
38
39 lf-infra-tox-install
40 --------------------
41
42 Install Tox into a virtualenv.
43
44 :Required Parameters:
45
46     :python-version: Version of Python to install into the Tox virtualenv.
47         Eg. python2 / python3
48
49 lf-infra-tox-sonar
50 ------------------
51
52 Runs Sonar scanning against a Python project.
53
54 :Required Parameters:
55
56     :java-version: Version of Java to use to run Sonar.
57     :mvn-version: Version of Maven to use to run Sonar.
58
59 lf-tox-install
60 --------------
61
62 Runs a shell script that installs tox in a Python virtualenv.
63
64 :Required Parameters:
65
66     :python-version: Base Python version to use in the virtualenv. For example
67         python2 or python3.
68
69
70 Job Templates
71 =============
72
73 Python XC CLM
74 -------------
75
76 CLM scans for Python based repos. This job will call the Nexus IQ CLI
77 directly to run the scans.
78
79 A new credential named "nexus-iq-xc-clm" needs to exist in the Jenkins credentials.
80 The credential should contain the username and password to access Nexus
81 IQ Server.
82
83 :Template Names:
84
85     - {project-name}-python-clm-{stream}
86     - gerrit-python-xc-clm
87     - github-python-xc-clm
88
89 :Required parameters:
90
91     :build-node: The node to run build on.
92     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
93         get configured in defaults.yaml)
94
95 :Optional parameters:
96
97     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
98     :nexus-iq-cli-version: Nexus IQ CLI package version to download and use. (default: 1.44.0-01)
99     :build-timeout: Timeout in seconds before aborting build. (default: 60)
100     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
101     :java-version: Version of Java to use for the build. (default: openjdk8)
102     :stream: Keyword used to represent a release code-name.
103         Often the same as the branch. (default: master)
104     :submodule-recursive: Whether to checkout submodules recursively.
105         (default: true)
106     :gerrit_clm_triggers: Override Gerrit Triggers.
107     :gerrit_trigger_file_paths: Override file paths which used to filter which
108         file modifications will trigger a build. Refer to JJB documentation for
109         "file-path" details.
110         https://docs.openstack.org/infra/jenkins-job-builder/triggers.html#triggers.gerrit
111
112
113 Python Sonar with Tox
114 ---------------------
115
116 Sonar scans for Python based repos. This job will perform a tox call which
117 runs the coverage command to gather tests results. These test results get
118 published back into Sonar after running the Sonar goals.
119
120 To get the Sonar coverage results, tox.ini needs to exist and configured
121 with coverage commands to run.
122
123 The coverage commands define the code that gets executed by the test suites.
124 It does not guarantee that the code tests executed properly, but it will help
125 pointing out the code that is not tested at all.
126
127 For example:
128
129 .. code-block:: bash
130
131     [testenv:py27]
132     commands =
133             coverage run --module pytest --junitxml xunit-results.xml
134             coverage xml --omit=".tox/py27/*","tests/*"
135             coverage report --omit=".tox/py27/*","tests/*"
136
137 For more details refer to coverage and sonar documentation:
138
139 https://coverage.readthedocs.io/
140
141 https://docs.sonarqube.org/display/PLUG/Python+Coverage+Results+Import
142
143 :Template Names:
144
145     - {project-name}-tox-sonar
146     - gerrit-tox-sonar
147     - github-tox-sonar
148
149 :Required parameters:
150
151     :build-node: The node to run build on.
152     :jenkins-ssh-credential: Credential to use for SSH. (Generally should
153         get configured in defaults.yaml)
154     :mvn-settings: The name of settings file containing credentials for the project.
155
156 :Optional parameters:
157
158     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
159     :build-timeout: Timeout in seconds before aborting build. (default: 60)
160     :cron: Cron schedule when to trigger the job. This parameter also
161         supports multiline input via YAML pipe | character in cases where
162         one may want to provide more than 1 cron timer.  (default: H 11 * * *
163         to run once a day)
164     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
165     :java-version: Version of Java to use for the build. (default: openjdk8)
166     :mvn-global-settings: The name of the Maven global settings to use for
167         Maven configuration. (default: global-settings)
168     :mvn-version: Version of maven to use. (default: mvn35)
169     :stream: Keyword used to represent a release code-name.
170         Often the same as the branch. (default: master)
171     :submodule-recursive: Whether to checkout submodules recursively.
172         (default: true)
173     :gerrit_sonar_triggers: Override Gerrit Triggers.
174     :gerrit_trigger_file_paths: Override file paths which used to filter which
175         file modifications will trigger a build. Refer to JJB documentation for
176         "file-path" details.
177         https://docs.openstack.org/infra/jenkins-job-builder/triggers.html#triggers.gerrit
178
179
180 Tox Verify
181 ----------
182
183 Tox runner to verify a project. This job is pyenv aware so if the image
184 contains an installation of pyenv at /opt/pyenv it will pick it up and run
185 Python tests with the appropriate Python versions. This job will set the
186 following pyenv variables before running.
187
188 .. code:: bash
189
190    export PYENV_ROOT="/opt/pyenv"
191    export PATH="$PYENV_ROOT/bin:$PATH"
192
193 :Template Names:
194
195     - {project-name}-tox-verify-{stream}
196     - gerrit-tox-verify
197     - github-tox-verify
198
199 :Required Parameters:
200
201     :build-node: The node to run build on.
202     :jenkins-ssh-credential: Credential to use for SSH. (Generally set
203         in defaults.yaml)
204
205 :Optional Parameters:
206
207     :branch: The branch to build against. (default: master)
208     :build-days-to-keep: Days to keep build logs in Jenkins. (default: 7)
209     :build-timeout: Timeout in seconds before aborting build. (default: 10)
210     :git-url: URL clone project from. (default: $GIT_URL/$PROJECT)
211     :python-version: Version of Python to configure as a base in virtualenv.
212         (default: python3)
213     :stream: Keyword representing a release code-name.
214         Often the same as the branch. (default: master)
215     :submodule-recursive: Whether to checkout submodules recursively.
216         (default: true)
217     :tox-dir: Directory containing the project's tox.ini relative to
218         the workspace. Empty works if tox.ini is at project root.
219         (default: '')
220     :tox-envs: Tox environments to run. If blank run everything described
221         in tox.ini. (default: '')
222     :gerrit_trigger_file_paths: Override file paths which used to filter which
223         file modifications will trigger a build. Refer to JJB documentation for
224         "file-path" details.
225         https://docs.openstack.org/infra/jenkins-job-builder/triggers.html#triggers.gerrit