diff --git a/jenkins_jobs/modules/view_list.py b/jenkins_jobs/modules/view_list.py index be61f5e30..8a32eadb9 100644 --- a/jenkins_jobs/modules/view_list.py +++ b/jenkins_jobs/modules/view_list.py @@ -27,11 +27,29 @@ to the :ref:`view_list` definition. * **filter-queue** (`bool`): Show only included jobs in builder queue. (default false) * **job-name** (`list`): List of jobs to be included. - * **job-filters** (`dict`): Job filters to be included. + * **job-filters** (`dict`): Job filters to be included. Requires + :jenkins-wiki:`View Job Filters ` + + * **most-recent** (`dict`) :most-recent: * **max-to-include** (`int`): Maximum number of jobs to include. (default 0) - * **check-start-time** (`bool`): Check job start time - (default false) + * **check-start-time** (`bool`): Check job start + time. (default false) + + * **build-duration** (`dict`) + :build-duration: * **match-type** ('str'): Jobs that match a filter + to include. (default includeMatched) + * **build-duration-type** ('str'): Duration of the + build. (default Latest) + * **amount-type**: ('str'): Duration in hours, + days or builds. (default Hours) + * **amount**: ('int'): How far back to check. + (default 0) + * **less-than**: ('bool'): Check build duration + less than or more than. (default True) + * **build-duration-minutes**: ('int'): Build + duration minutes. (default 0) + * **columns** (`list`): List of columns to be shown in view. * **regex** (`str`): . Regular expression for selecting jobs (optional) @@ -106,19 +124,35 @@ class List(jenkins_jobs.modules.base.Base): job_filter_xml = XML.SubElement(root, 'jobFilters') jobfilters = data.get('job-filters', []) - mapping = [ - ('max-to-include', 'maxToInclude', '0'), - ('check-start-time', 'checkStartTime', False), - ] - for jobfilter in jobfilters: - if 'most-recent' in jobfilter: + if jobfilter == 'most-recent': mr_xml = XML.SubElement(job_filter_xml, - 'hudson.views.MostRecentJobsFilter') + 'hudson.views.MostRecentJobsFilter') mr_xml.set('plugin', 'view-job-filters') - mr_data = jobfilter.get('most-recent') + mr_data = jobfilters.get('most-recent') + mapping = [ + ('max-to-include', 'maxToInclude', '0'), + ('check-start-time', 'checkStartTime', False), + ] convert_mapping_to_xml(mr_xml, mr_data, mapping, - fail_required=True) + fail_required=True) + + if jobfilter == 'build-duration': + bd_xml = XML.SubElement(job_filter_xml, + 'hudson.views.BuildDurationFilter') + bd_xml.set('plugin', 'view-job-filters') + bd_data = jobfilters.get('build-duration') + mapping = [ + ('match-type', 'includeExcludeTypeString', + 'includeMatched'), + ('build-duration-type', 'buildCountTypeString', 'Latest'), + ('amount-type', 'amountTypeString', 'Hours'), + ('amount', 'amount', '0'), + ('less-than', 'lessThan', True), + ('build-duration-minutes', 'buildDurationMinutes', '0'), + ] + convert_mapping_to_xml(bd_xml, bd_data, mapping, + fail_required=True) c_xml = XML.SubElement(root, 'columns') columns = data.get('columns', DEFAULT_COLUMNS) diff --git a/tests/views/fixtures/view_list_build_duration_full.xml b/tests/views/fixtures/view_list_build_duration_full.xml new file mode 100644 index 000000000..ee2c17754 --- /dev/null +++ b/tests/views/fixtures/view_list_build_duration_full.xml @@ -0,0 +1,32 @@ + + + list-view-name01 + Sample description + true + true + + + + + + + includeMatched + Latest + Hours + 5.0 + true + 50.0 + + + + + + + + + + + + true + false + diff --git a/tests/views/fixtures/view_list_build_duration_full.yaml b/tests/views/fixtures/view_list_build_duration_full.yaml new file mode 100644 index 000000000..f482d33dd --- /dev/null +++ b/tests/views/fixtures/view_list_build_duration_full.yaml @@ -0,0 +1,15 @@ +name: list-view-name01 +view-type: list +description: 'Sample description' +filter-executors: true +filter-queue: true +job-filters: + build-duration: + match-type: includeMatched + build-duration-type: Latest + amount-type: Hours + amount: 5.0 + less-then: true + build-duration-minutes: 50.0 +recurse: true +status-filter: false diff --git a/tests/views/fixtures/view_list_build_duration_min.xml b/tests/views/fixtures/view_list_build_duration_min.xml new file mode 100644 index 000000000..af8d15de7 --- /dev/null +++ b/tests/views/fixtures/view_list_build_duration_min.xml @@ -0,0 +1,32 @@ + + + list-view-name01 + Sample description + true + true + + + + + + + includeMatched + Latest + Hours + 0 + true + 0 + + + + + + + + + + + + true + false + diff --git a/tests/views/fixtures/view_list_build_duration_min.yaml b/tests/views/fixtures/view_list_build_duration_min.yaml new file mode 100644 index 000000000..ad3573038 --- /dev/null +++ b/tests/views/fixtures/view_list_build_duration_min.yaml @@ -0,0 +1,10 @@ +name: list-view-name01 +view-type: list +description: 'Sample description' +filter-executors: true +filter-queue: true +job-filters: + build-duration: + build-duration-type: Latest +recurse: true +status-filter: false diff --git a/tests/views/fixtures/view_most_recent_full.yaml b/tests/views/fixtures/view_most_recent_full.yaml index 3027ba1b1..263096a7d 100644 --- a/tests/views/fixtures/view_most_recent_full.yaml +++ b/tests/views/fixtures/view_most_recent_full.yaml @@ -4,8 +4,8 @@ description: 'Sample description' filter-executors: true filter-queue: true job-filters: - - most-recent: - max-to-include: 25 - check-start-time: true + most-recent: + max-to-include: 25 + check-start-time: true recurse: true status-filter: false