diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index eb2e0d965..fb91b9fe6 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -1066,16 +1066,16 @@ def junit(registry, xml_parent, data): """yaml: junit Publish JUnit test results. - :arg str results: results filename + :arg str results: results filename (required) :arg bool keep-long-stdio: Retain long standard output/error in test - results (default true). + results (default true). :arg bool allow-empty-results: Do not fail builds if no junit reports - are found (default false) + are found (default false) :arg float health-scale-factor: Amplification factor to apply to test - failures when computing the test result contribution to the build health - score. (default 1.0) + failures when computing the test result contribution to the build + health score. (default 1.0) :arg bool allow-empty-results: Do not fail the build if the JUnit files are - missing (default false). + missing (default false). :arg bool test-stability: Add historical information about test results stability (default false). Requires the Jenkins :jenkins-wiki:`Test stability Plugin @@ -1102,15 +1102,15 @@ def junit(registry, xml_parent, data): junitresult = XML.SubElement(xml_parent, 'hudson.tasks.junit.JUnitResultArchiver') junitresult.set('plugin', 'junit') - XML.SubElement(junitresult, 'testResults').text = data['results'] - XML.SubElement(junitresult, 'keepLongStdio').text = str( - data.get('keep-long-stdio', True)).lower() - XML.SubElement(junitresult, 'allowEmptyResults').text = str( - data.get('allow-empty-results', False)).lower() - XML.SubElement(junitresult, 'healthScaleFactor').text = str( - data.get('health-scale-factor', '1.0')) - XML.SubElement(junitresult, 'allowEmptyResults').text = str( - data.get('allow-empty-results', False)).lower() + mapping = [ + ('results', 'testResults', None), + ('keep-long-stdio', 'keepLongStdio', True), + ('health-scale-factor', 'healthScaleFactor', '1.0'), + ('allow-empty-results', 'allowEmptyResults', False), + ] + helpers.convert_mapping_to_xml( + junitresult, data, mapping, fail_required=True) + datapublisher = XML.SubElement(junitresult, 'testDataPublishers') if str(data.get('test-stability', False)).lower() == 'true': XML.SubElement(datapublisher, diff --git a/tests/publishers/fixtures/junit001.xml b/tests/publishers/fixtures/junit001.xml index 04a424d8d..fc1db95b1 100644 --- a/tests/publishers/fixtures/junit001.xml +++ b/tests/publishers/fixtures/junit001.xml @@ -4,7 +4,6 @@ nosetests.xml true - false 1.0 false diff --git a/tests/publishers/fixtures/junit002.xml b/tests/publishers/fixtures/junit002.xml index 33153e756..cb1686266 100644 --- a/tests/publishers/fixtures/junit002.xml +++ b/tests/publishers/fixtures/junit002.xml @@ -4,7 +4,6 @@ nosetests-example.xml false - true 2.0 true