Debian Codegraph @

jenkins_jobs/modules/view_list.py

raw
1 # Copyright 2015 Openstack Foundation
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 """
16 The view list module handles creating Jenkins List views.
17
18 To create a list view specify ``list`` in the ``view-type`` attribute
19 to the :ref:`view_list` definition.
20
21 :View Parameters:
22 * **name** (`str`): The name of the view.
23 * **view-type** (`str`): The type of view.
24 * **description** (`str`): A description of the view. (default '')
25 * **filter-executors** (`bool`): Show only executors that can
26 execute the included views. (default false)
27 * **filter-queue** (`bool`): Show only included jobs in builder
28 queue. (default false)
29 * **job-name** (`list`): List of jobs to be included.
30 * **job-filters** (`dict`): Job filters to be included. Requires
31 :jenkins-plugins:`View Job Filters <view-job-filters>`
32
33 * **most-recent** (`dict`)
34 :most-recent:
35 * **max-to-include** (`int`): Maximum number of jobs
36 to include. (default 0)
37 * **check-start-time** (`bool`): Check job start
38 time. (default false)
39
40 * **build-duration** (`dict`)
41 :build-duration:
42 * **match-type** ('str'): Jobs that match a filter
43 to include. (default includeMatched)
44 * **build-duration-type** ('str'): Duration of the
45 build. (default Latest)
46 * **amount-type**: ('str'): Duration in hours,
47 days or builds. (default Hours)
48 * **amount**: ('int'): How far back to check.
49 (default 0)
50 * **less-than**: ('bool'): Check build duration
51 less than or more than. (default True)
52 * **build-duration-minutes**: ('int'): Build
53 duration minutes. (default 0)
54
55 * **build-trend** (`dict`)
56 :build-trend:
57 * **match-type** ('str'): Jobs that match a filter
58 to include. (default includeMatched)
59 * **build-trend-type** ('str'): Duration of the
60 build. (default Latest)
61 * **amount-type**: ('str'): Duration in hours,
62 days or builds. (default Hours)
63 * **amount**: ('int'): How far back to check.
64 (default 0)
65 * **status**: ('str'): Job status.
66 (default Completed)
67
68 * **job-status** (`dict`)
69 :job-status:
70 * **match-type** ('str'): Jobs that match a filter
71 to include. (default includeMatched)
72 * **unstable** ('bool'): Jobs with status
73 unstable. (default False)
74 * **failed** ('bool'): Jobs with status
75 failed. (default False)
76 * **aborted** ('bool'): Jobs with status
77 aborted. (default False)
78 * **disabled** ('bool'): Jobs with status
79 disabled. (default False)
80 * **stable** ('bool'): Jobs with status
81 stable. (default False)
82
83 * **fallback** (`dict`)
84 :fallback:
85 * **fallback-type** ('str'): Fallback type to include/exclude
86 for all jobs in a view, if no jobs have been included by
87 previous filters. (default REMOVE_ALL_IF_ALL_INCLUDED)
88
89 * **build-status** (`dict`)
90 :build-status:
91 * **match-type** ('str'): Jobs that match a filter
92 to include. (default includeMatched)
93 * **never-built** ('bool'): Jobs that are never
94 built. (default False)
95 * **building** ('bool'): Jobs that are being
96 built. (default False)
97 * **in-build-queue** ('bool'): Jobs that are in
98 the build queue. (default False)
99
100 * **user-relevence** (`dict`)
101 :user-relevence:
102 * **match-type** ('str'): Jobs that match a filter
103 to include. (default includeMatched)
104 * **build-count** ('str'): Count of builds.
105 (default AtLeastOne)
106 * **amount-type**: ('str'): Duration in hours,
107 days or builds. (default Hours)
108 * **amount**: ('int'): How far back to check.
109 (default 0)
110 * **match-user-id** ('bool'): Jobs matching
111 user-id. (default False)
112 * **match-user-fullname** ('bool'): Jobs
113 matching user fullname. (default False)
114 * **ignore-case** ('bool'): Ignore case.
115 (default False)
116 * **ignore-whitespace** ('bool'): Ignore
117 whitespace. (default False)
118 * **ignore-non-alphaNumeric** ('bool'): Ignore
119 non-alphaNumeric. (default False)
120 * **match-builder** ('bool'): Jobs matching
121 builder. (default False)
122 * **match-email** ('bool'): Jobs matching
123 email. (default False)
124 * **match-scm-changes** ('bool'): Jobs matching
125 scm changes. (default False)
126
127 * **regex-job** (`dict`)
128 :regex-job:
129 * **match-type** ('str'): Jobs that match a filter
130 to include. (default includeMatched)
131 * **regex-name** ('str'): Regular expression name.
132 (default '')
133 * **regex** ('str'): Regular expression. (default '')
134
135 * **job-tpye** (`dict`)
136 :job-type:
137 * **match-type** ('str'): Jobs that match a filter to include.
138 (default includeMatched)
139 * **job-type** ('str'): Type of Job.
140 (default hudson.model.FreeStyleProject)
141
142 * **parameter** (`dict`)
143 :parameter:
144 * **match-type** ('str'): Jobs that match a filter to include.
145 (default includeMatched)
146 * **name** ('str'): Job name to match. (default '')
147 * **value** ('str'): Value to match. (default '')
148 * **desc** ('str'): Description to match. (default '')
149 * **use-default-value** ('bool'): Use default value.
150 (default False)
151 * **match-builds-in-progress** ('bool'): Match build in
152 progress. (default False)
153 * **match-all-builds** ('bool'): Match all builds.
154 (default False)
155 * **max-builds-to-match** ('int'): Maximum builds to match.
156 (default 0)
157
158 * **other-views** (`dict`)
159 :other-views:
160 * **match-type** ('str'): Jobs that match a filter
161 to include. (default includeMatched)
162 * **view-name** ('str'): View name.
163 (default select a view other than this one)
164
165 * **scm** (`dict`)
166 :scm:
167 * **match-type** ('str'): Jobs that match a filter to include.
168 (default includeMatched)
169 * **scm-type** ('str'): Type of SCM.
170 (default hudson.scm.NullSCM)
171
172 * **secured-job** (`dict`)
173 :secured-job:
174 * **match-type** ('str'): Jobs that match a filter
175 to include. (default includeMatched)
176
177 * **user-permissions** (`dict`)
178 :user-permissions:
179 * **match-type** ('str'): Jobs that match a filter to include.
180 (default includeMatched)
181 * **configure** ('bool'): User with configure permissions.
182 (default false)
183 * **amount-type**: ('bool'): User with build permissions.
184 (default false)
185 * **amount**: ('bool'): User with workspace permissions.
186 (default false)
187 * **permission-check**: ('str'): Match user permissions.
188 (default MustMatchAll)
189
190 * **upstream-downstream** (`dict`)
191 :upstream-downstream:
192 * **include-upstream** ('bool'): Jobs that match upstream.
193 (default False)
194 * **include-downstream** ('bool'): Jobs that match downstream.
195 (default False)
196 * **recursive** ('bool'): Jobs that are recursive.
197 (default False)
198 * **exclude-originals** ('bool'): Jobs that are originals.
199 (default False)
200
201 * **unclassified** (`dict`)
202 :unclassified:
203 * **match-type** ('str'): Jobs that match a filter to include.
204 (default includeMatched)
205
206 * **columns** (`list`): List of columns to be shown in view.
207 * **regex** (`str`): . Regular expression for selecting jobs
208 (optional)
209 * **recurse** (`bool`): Recurse in subfolders.(default false)
210 * **status-filter** (`bool`): Filter job list by enabled/disabled
211 status. (optional)
212
213 Example:
214
215 .. literalinclude::
216 /../../tests/views/fixtures/view_list001.yaml
217
218 Example:
219
220 .. literalinclude::
221 /../../tests/views/fixtures/view_list002.yaml
222 """
223
224 import xml.etree.ElementTree as XML
225 import jenkins_jobs.modules.base
226 import jenkins_jobs.modules.helpers as helpers
227 import jenkins_jobs.modules.view_jobfilters as view_jobfilters
228
229 COLUMN_DICT = {
230 "status": "hudson.views.StatusColumn",
231 "weather": "hudson.views.WeatherColumn",
232 "job": "hudson.views.JobColumn",
233 "last-success": "hudson.views.LastSuccessColumn",
234 "last-failure": "hudson.views.LastFailureColumn",
235 "last-duration": "hudson.views.LastDurationColumn",
236 "build-button": "hudson.views.BuildButtonColumn",
237 "last-stable": "hudson.views.LastStableColumn",
238 "robot-list": "hudson.plugins.robot.view.RobotListViewColumn",
239 "find-bugs": "hudson.plugins.findbugs.FindBugsColumn",
240 "jacoco": "hudson.plugins.jacococoveragecolumn.JaCoCoColumn",
241 "git-branch": "hudson.plugins.git.GitBranchSpecifierColumn",
242 "favorite": "hudson.plugins.favorite.column.FavoriteColumn",
243 "schedule-build": "org.jenkinsci.plugins.schedulebuild.ScheduleBuildButtonColumn",
244 "priority-sorter": "jenkins.advancedqueue.PrioritySorterJobColumn",
245 "build-filter": "hudson.views.BuildFilterColumn",
246 "desc": "jenkins.branch.DescriptionColumn",
247 "policy-violations": "com.sonatype.insight.ci.hudson.QualityColumn "
248 'plugin="sonatype-clm-ci"',
249 "member-graph-view": "com.barchart.jenkins.cascade.GraphViewColumn "
250 'plugin="maven-release-cascade"',
251 "built-on": [
252 ["org.jenkins.plugins.builton.BuiltOnColumn", {"plugin": "built-on-column"}]
253 ],
254 "extra-tests-total": [
255 ["jenkins.plugins.extracolumns.TestResultColumn", {"plugin": "extra-columns"}],
256 "<testResultFormat>2</testResultFormat>",
257 ],
258 "extra-tests-failed": [
259 ["jenkins.plugins.extracolumns.TestResultColumn", {"plugin": "extra-columns"}],
260 "<testResultFormat>3</testResultFormat>",
261 ],
262 "extra-tests-passed": [
263 ["jenkins.plugins.extracolumns.TestResultColumn", {"plugin": "extra-columns"}],
264 "<testResultFormat>4</testResultFormat>",
265 ],
266 "extra-tests-skipped": [
267 ["jenkins.plugins.extracolumns.TestResultColumn", {"plugin": "extra-columns"}],
268 "<testResultFormat>5</testResultFormat>",
269 ],
270 "extra-tests-format-0": [
271 ["jenkins.plugins.extracolumns.TestResultColumn", {"plugin": "extra-columns"}],
272 "<testResultFormat>0</testResultFormat>",
273 ],
274 "extra-tests-format-1": [
275 ["jenkins.plugins.extracolumns.TestResultColumn", {"plugin": "extra-columns"}],
276 "<testResultFormat>1</testResultFormat>",
277 ],
278 "extra-build-description": [
279 [
280 "jenkins.plugins.extracolumns.BuildDescriptionColumn",
281 {"plugin": "extra-columns"},
282 ],
283 "<columnWidth>3</columnWidth>",
284 "<forceWidth>false</forceWidth>",
285 ],
286 "extra-build-parameters": [
287 [
288 "jenkins.plugins.extracolumns.BuildParametersColumn",
289 {"plugin": "extra-columns"},
290 ],
291 "<singlePara>false</singlePara>",
292 "<parameterName/>",
293 ],
294 "extra-last-user-name": "jenkins.plugins.extracolumns.UserNameColumn"
295 ' plugin="extra-columns"',
296 "extra-last-output": "jenkins.plugins.extracolumns.LastBuildConsoleColumn"
297 ' plugin="extra-columns"',
298 "extra-workspace-link": "jenkins.plugins.extracolumns.WorkspaceColumn "
299 'plugin="extra-columns"',
300 "extra-configure-button": "jenkins.plugins.extracolumns.ConfigureProjectColumn"
301 ' plugin="extra-columns"',
302 }
303 DEFAULT_COLUMNS = [
304 "status",
305 "weather",
306 "job",
307 "last-success",
308 "last-failure",
309 "last-duration",
310 "build-button",
311 ]
312
313
314 class List(jenkins_jobs.modules.base.Base):
315 sequence = 0
316
317 def root_xml(self, data, sectioned=False):
318 name = "hudson.model.ListView"
319 if sectioned:
320 name = "hudson.plugins.sectioned__view.ListViewSection"
321 root = XML.Element(name)
322
323 mapping = [("name", "name", None)]
324 if not sectioned:
325 mapping.extend(
326 [
327 ("description", "description", ""),
328 ("filter-executors", "filterExecutors", False),
329 ("filter-queue", "filterQueue", False),
330 ]
331 )
332 helpers.convert_mapping_to_xml(root, data, mapping, fail_required=True)
333
334 if not sectioned:
335 XML.SubElement(
336 root, "properties", {"class": "hudson.model.View$PropertyList"}
337 )
338
339 jn_xml = XML.SubElement(root, "jobNames")
340 jobnames = data.get("job-name", None)
341 XML.SubElement(
342 jn_xml, "comparator", {"class": "hudson.util.CaseInsensitiveComparator"}
343 )
344 if jobnames is not None:
345 # Job names must be sorted in the xml
346 jobnames = sorted(jobnames, key=str.lower)
347 for jobname in jobnames:
348 XML.SubElement(jn_xml, "string").text = str(jobname)
349
350 job_filter_xml = XML.SubElement(root, "jobFilters")
351 jobfilters = data.get("job-filters", [])
352
353 for jobfilter in jobfilters:
354 filter = getattr(view_jobfilters, jobfilter.replace("-", "_"))
355 filter(job_filter_xml, jobfilters.get(jobfilter))
356
357 if sectioned:
358 mapping = [
359 ("width", "width", "FULL", ["FULL", "HALF", "THIRD", "TWO_THIRDS"]),
360 ("alignment", "alignment", "CENTER", ["CENTER", "LEFT", "RIGHT"]),
361 ]
362 helpers.convert_mapping_to_xml(root, data, mapping, fail_required=True)
363
364 c_xml = XML.SubElement(root, "columns")
365 columns = data.get("columns", DEFAULT_COLUMNS)
366
367 for column in columns:
368 if isinstance(column, dict):
369 if "extra-build-parameter" in column:
370 p_name = column["extra-build-parameter"]
371 x = XML.SubElement(
372 c_xml,
373 "jenkins.plugins.extracolumns.BuildParametersColumn",
374 plugin="extra-columns",
375 )
376 x.append(XML.fromstring("<singlePara>true</singlePara>"))
377 x.append(
378 XML.fromstring("<parameterName>%s</parameterName>" % p_name)
379 )
380 else:
381 if column in COLUMN_DICT:
382 if isinstance(COLUMN_DICT[column], list):
383 x = XML.SubElement(
384 c_xml,
385 COLUMN_DICT[column][0][0],
386 **COLUMN_DICT[column][0][1]
387 )
388 for tag in COLUMN_DICT[column][1:]:
389 x.append(XML.fromstring(tag))
390 else:
391 XML.SubElement(c_xml, COLUMN_DICT[column])
392 mapping = [("regex", "includeRegex", None)]
393 if not sectioned:
394 mapping.extend(
395 [("recurse", "recurse", False), ("status-filter", "statusFilter", None)]
396 )
397 helpers.convert_mapping_to_xml(root, data, mapping, fail_required=False)
398
399 return root