Skip to content

Instantly share code, notes, and snippets.

@tenpn
Created October 2, 2025 09:28
Show Gist options
  • Select an option

  • Save tenpn/54afaadd1e5f9975a84dabeb94f00a65 to your computer and use it in GitHub Desktop.

Select an option

Save tenpn/54afaadd1e5f9975a84dabeb94f00a65 to your computer and use it in GitHub Desktop.
jenkins unreal -> junit conversion
// some of this via https://unrealcommunity.wiki/jenkins-ci-amp-test-driven-development-6912tx0c
def convertTestsReport(String unrealReportDir, String outputFileName) {
def jsonReport = readFile file: "${unrealReportDir}\\index.json", encoding: "UTF-8"
// Needed because the JSON is encoded in UTF-8 with BOM
jsonReport = jsonReport.replace( "\uFEFF", "" );
def xmlContent = transformReport( jsonReport )
writeFile file: "${unrealReportDir}\\${outputFileName}", text: xmlContent.toString()
}
import groovy.json.JsonSlurper
import groovy.xml.MarkupBuilder
@NonCPS//atomic method
def transformReport( String jsonContent ) {
def parsedReport = new JsonSlurper().parseText( jsonContent )
def jUnitReport = new StringWriter()
def builder = new MarkupBuilder( jUnitReport )
builder.doubleQuotes = true
builder.mkp.xmlDeclaration version: "1.0", encoding: "utf-8"
builder.testsuite( tests: parsedReport.succeeded + parsedReport.failed, failures: parsedReport.failed, time: parsedReport.totalDuration ) {
for ( test in parsedReport.tests ) {
builder.testcase( name: test.testDisplayName, classname: test.fullTestPath, status: test.state ) {
if(test.state == "Fail") {
for ( entry in test.entries ) {
if(entry.event.type == "Error") {
builder.failure( message: entry.event.message, type: entry.event.type, entry.filename + " " + entry.lineNumber )
}
}
}
}
}
}
return jUnitReport.toString()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment