diff --git a/jenkins_jobs/modules/properties.py b/jenkins_jobs/modules/properties.py index 65a10c3d4..ae794f5ae 100644 --- a/jenkins_jobs/modules/properties.py +++ b/jenkins_jobs/modules/properties.py @@ -497,17 +497,33 @@ def priority_sorter(registry, xml_parent, data): `. :arg int priority: Priority of the job. Higher value means higher - priority, with 100 as the standard priority. (required) + priority, with 3 as the default priority. (required) Example: - .. literalinclude:: /../../tests/properties/fixtures/priority_sorter.yaml + .. literalinclude:: + /../../tests/properties/fixtures/priority_sorter002.yaml :language: yaml """ - priority_sorter_tag = XML.SubElement(xml_parent, - 'hudson.queueSorter.' - 'PrioritySorterJobProperty') - mapping = [('priority', 'priority', None)] + plugin_info = registry.get_plugin_info('Priority Sorter Plugin') + version = pkg_resources.parse_version(plugin_info.get('version', '0')) + + if version >= pkg_resources.parse_version("2.0"): + priority_sorter_tag = XML.SubElement(xml_parent, + 'jenkins.advancedqueue.priority.' + 'strategy.PriorityJobProperty') + + mapping = [ + ('use', 'useJobPriority', True), + ('priority', 'priority', None) + ] + else: + priority_sorter_tag = XML.SubElement(xml_parent, + 'hudson.queueSorter.' + 'PrioritySorterJobProperty') + + mapping = [('priority', 'priority', None)] + helpers.convert_mapping_to_xml( priority_sorter_tag, data, mapping, fail_required=True) diff --git a/tests/properties/fixtures/priority_sorter001.plugins_info.yaml b/tests/properties/fixtures/priority_sorter001.plugins_info.yaml new file mode 100644 index 000000000..c1adba087 --- /dev/null +++ b/tests/properties/fixtures/priority_sorter001.plugins_info.yaml @@ -0,0 +1,3 @@ +- longName: 'Priority Sorter Plugin' + shortName: 'PrioritySorter' + version: '1.0' diff --git a/tests/properties/fixtures/priority_sorter.xml b/tests/properties/fixtures/priority_sorter001.xml similarity index 100% rename from tests/properties/fixtures/priority_sorter.xml rename to tests/properties/fixtures/priority_sorter001.xml diff --git a/tests/properties/fixtures/priority_sorter.yaml b/tests/properties/fixtures/priority_sorter001.yaml similarity index 100% rename from tests/properties/fixtures/priority_sorter.yaml rename to tests/properties/fixtures/priority_sorter001.yaml diff --git a/tests/properties/fixtures/priority_sorter002.plugins_info.yaml b/tests/properties/fixtures/priority_sorter002.plugins_info.yaml new file mode 100644 index 000000000..d4045458e --- /dev/null +++ b/tests/properties/fixtures/priority_sorter002.plugins_info.yaml @@ -0,0 +1,3 @@ +- longName: 'Priority Sorter Plugin' + shortName: 'PrioritySorter' + version: '2.0' diff --git a/tests/properties/fixtures/priority_sorter002.xml b/tests/properties/fixtures/priority_sorter002.xml new file mode 100644 index 000000000..1e569759c --- /dev/null +++ b/tests/properties/fixtures/priority_sorter002.xml @@ -0,0 +1,9 @@ + + + + + true + 3 + + + diff --git a/tests/properties/fixtures/priority_sorter002.yaml b/tests/properties/fixtures/priority_sorter002.yaml new file mode 100644 index 000000000..10c53ad9b --- /dev/null +++ b/tests/properties/fixtures/priority_sorter002.yaml @@ -0,0 +1,3 @@ +properties: + - priority-sorter: + priority: 3