summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2019-05-31 15:23:31 (GMT)
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2019-06-03 15:03:27 (GMT)
commit3a99d20a918c9678f3cce4a38aef8aadb87a36ad (patch)
treefac7110349a3da83a85a14ea41c44b25126b84a1
parentec51dd2191508ec7442964bf82b913077f041aad (diff)
downloadjenkins-lib-3a99d20a918c9678f3cce4a38aef8aadb87a36ad.zip
jenkins-lib-3a99d20a918c9678f3cce4a38aef8aadb87a36ad.tar.gz
jenkins-lib-3a99d20a918c9678f3cce4a38aef8aadb87a36ad.tar.bz2
add a mergeJunitResults step (#30427)HEADmaster
-rwxr-xr-xresources/merge-junit-results.py65
-rw-r--r--vars/mergeJunitResults.groovy9
2 files changed, 74 insertions, 0 deletions
diff --git a/resources/merge-junit-results.py b/resources/merge-junit-results.py
new file mode 100755
index 0000000..a50bc7f
--- /dev/null
+++ b/resources/merge-junit-results.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+#
+# Corey Goldberg, Dec 2012
+#
+
+import os
+import sys
+import xml.etree.ElementTree as ET
+
+
+"""Merge multiple JUnit XML files into a single results file.
+Output dumps to sdtdout.
+example usage:
+ $ python merge_junit_results.py results1.xml results2.xml > results.xml
+"""
+
+
+def main():
+ args = sys.argv[1:]
+ if not args:
+ usage()
+ sys.exit(2)
+ if '-h' in args or '--help' in args:
+ usage()
+ sys.exit(2)
+ merge_results(args[:])
+
+
+def merge_results(xml_files):
+ failures = 0
+ tests = 0
+ errors = 0
+ time = 0.0
+ cases = []
+
+ for file_name in xml_files:
+ tree = ET.parse(file_name)
+ test_suite = tree.getroot()
+ failures += int(test_suite.attrib['failures'])
+ tests += int(test_suite.attrib['tests'])
+ errors += int(test_suite.attrib['errors'])
+ time += float(test_suite.attrib['time'])
+ name = test_suite.attrib.get('name', '')
+ for child in test_suite.getchildren():
+ child.attrib['classname'] = '%s-%s' % (name, child.attrib.get('classname', ''))
+ cases.append(test_suite.getchildren())
+
+ new_root = ET.Element('testsuite')
+ new_root.attrib['failures'] = '%s' % failures
+ new_root.attrib['tests'] = '%s' % tests
+ new_root.attrib['errors'] = '%s' % errors
+ new_root.attrib['time'] = '%s' % time
+ for case in cases:
+ new_root.extend(case)
+ new_tree = ET.ElementTree(new_root)
+ ET.dump(new_tree)
+
+
+def usage():
+ this_file = os.path.basename(__file__)
+ print('Usage: %s results1.xml results2.xml' % this_file)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/vars/mergeJunitResults.groovy b/vars/mergeJunitResults.groovy
new file mode 100644
index 0000000..56495be
--- /dev/null
+++ b/vars/mergeJunitResults.groovy
@@ -0,0 +1,9 @@
+def request = libraryResource 'com/mycorp/pipeline/somelib/request.json'
+
+def call() {
+ tmpdir = env.TMPDIR ? env.TMPDIR : '.'
+ writeFile file:"${tmpdir}/merge-junit-results.py", text: libraryResource('merge-junit-results.py')
+ sh "python ${tmpdir}/merge-junit-results.py junit-*.xml >junit.xml"
+ sh 'rm junit-*.xml'
+ junit 'junit.xml'
+}