diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py index b5a1a7fc7..55a6d1c38 100644 --- a/jenkins_jobs/modules/builders.py +++ b/jenkins_jobs/modules/builders.py @@ -4694,6 +4694,9 @@ def xunit(registry, xml_parent, data): :language: yaml """ + info = registry.get_plugin_info("xunit") + plugin_version = pkg_resources.parse_version(info.get("version", str(sys.maxsize))) + logger = logging.getLogger(__name__) xunit = XML.SubElement(xml_parent, "org.jenkinsci.plugins.xunit.XUnitBuilder") xunit.set("plugin", "xunit") @@ -4733,7 +4736,13 @@ def xunit(registry, xml_parent, data): supported_types.append(configured_type) # Generate XML for each of the supported framework types - xmltypes = XML.SubElement(xunit, "types") + # Note: versions 3+ are now using the 'tools' sub-element instead of 'types' + if plugin_version < pkg_resources.parse_version("3.0.0"): + types_name = "types" + else: + types_name = "tools" + + xmltypes = XML.SubElement(xunit, types_name) mappings = [ ("pattern", "pattern", ""), ("requireupdate", "failIfNotNew", True), diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 098f0828c..90fc2852f 100755 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -1832,6 +1832,9 @@ def xunit(registry, xml_parent, data): :language: yaml """ + info = registry.get_plugin_info("xunit") + plugin_version = pkg_resources.parse_version(info.get("version", str(sys.maxsize))) + logger = logging.getLogger(__name__) xunit = XML.SubElement(xml_parent, "xunit") xunit.set("plugin", "xunit") @@ -1871,7 +1874,13 @@ def xunit(registry, xml_parent, data): supported_types.append(configured_type) # Generate XML for each of the supported framework types - xmltypes = XML.SubElement(xunit, "types") + # Note: versions 3+ are now using the 'tools' sub-element instead of 'types' + if plugin_version < pkg_resources.parse_version("3.0.0"): + types_name = "types" + else: + types_name = "tools" + + xmltypes = XML.SubElement(xunit, types_name) for supported_type in supported_types: framework_name = next(iter(supported_type.keys())) xmlframework = XML.SubElement(xmltypes, types_to_plugin_types[framework_name]) diff --git a/tests/builders/fixtures/xunit-full.plugins_info.yaml b/tests/builders/fixtures/xunit-full.plugins_info.yaml new file mode 120000 index 000000000..380bb798c --- /dev/null +++ b/tests/builders/fixtures/xunit-full.plugins_info.yaml @@ -0,0 +1 @@ +../../publishers/fixtures/xunit001.plugins_info.yaml \ No newline at end of file diff --git a/tests/builders/fixtures/xunit-minimal.plugins_info.yaml b/tests/builders/fixtures/xunit-minimal.plugins_info.yaml new file mode 120000 index 000000000..380bb798c --- /dev/null +++ b/tests/builders/fixtures/xunit-minimal.plugins_info.yaml @@ -0,0 +1 @@ +../../publishers/fixtures/xunit001.plugins_info.yaml \ No newline at end of file diff --git a/tests/publishers/fixtures/xunit001.plugins_info.yaml b/tests/publishers/fixtures/xunit001.plugins_info.yaml new file mode 100644 index 000000000..f937793c7 --- /dev/null +++ b/tests/publishers/fixtures/xunit001.plugins_info.yaml @@ -0,0 +1,3 @@ +- longName: 'xUnit' + shortName: 'xunit' + version: "2.4.0" diff --git a/tests/publishers/fixtures/xunit002.plugins_info.yaml b/tests/publishers/fixtures/xunit002.plugins_info.yaml new file mode 120000 index 000000000..46c091505 --- /dev/null +++ b/tests/publishers/fixtures/xunit002.plugins_info.yaml @@ -0,0 +1 @@ +xunit001.plugins_info.yaml \ No newline at end of file diff --git a/tests/publishers/fixtures/xunit003.plugins_info.yaml b/tests/publishers/fixtures/xunit003.plugins_info.yaml new file mode 120000 index 000000000..46c091505 --- /dev/null +++ b/tests/publishers/fixtures/xunit003.plugins_info.yaml @@ -0,0 +1 @@ +xunit001.plugins_info.yaml \ No newline at end of file diff --git a/tests/publishers/fixtures/xunit004.plugins_info.yaml b/tests/publishers/fixtures/xunit004.plugins_info.yaml new file mode 100644 index 000000000..ba110c271 --- /dev/null +++ b/tests/publishers/fixtures/xunit004.plugins_info.yaml @@ -0,0 +1,3 @@ +- longName: 'xUnit' + shortName: 'xunit' + version: "3.0.0" diff --git a/tests/publishers/fixtures/xunit004.xml b/tests/publishers/fixtures/xunit004.xml new file mode 100644 index 000000000..e76b123e9 --- /dev/null +++ b/tests/publishers/fixtures/xunit004.xml @@ -0,0 +1,21 @@ + + + + + + + junit.log + true + true + false + true + + + + 1 + + 3000 + + + + diff --git a/tests/publishers/fixtures/xunit004.yaml b/tests/publishers/fixtures/xunit004.yaml new file mode 100644 index 000000000..ce446fa56 --- /dev/null +++ b/tests/publishers/fixtures/xunit004.yaml @@ -0,0 +1,5 @@ +publishers: + - xunit: + types: + - phpunit: + pattern: "junit.log"