Colin Laws
Colin Laws

Reputation: 680

How to perform XSLT on XML file in VSTS (Azure DevOps) using Saxon?

I am working in Visual Studio Team Services (now Azure DevOps). I am running PHPUnit and exporting test results as JUnit for VSTS to consume; however, I receive an error when attempting to run the PublishTestResults task with the PHPUnit XML file:

"##[warning]Invalid results file. Make sure the result format of the file '/home/vsts/work/1/s/styled-results.xml' matches 'JUnit' test results format."

So after a long time researching the problem, I found one other person attempting to publish a PHPUnit generated JUnit file to VSTS here. It turns out that they simply don't support the output of PHPUnit. A community member has posted this gist of an XSL file to transform the XML into a format that VSTS (Azure DevOps) will understand.

The creator of the gist mentioned that he used saxonb in a script task on VSTS to process the XSLT. I have no idea how to run saxonb on VSTS. I don't know the name of the executable to call, the options, etc. I tried the Saxon docs, but I can't seem to get this working on a VSTS Ubuntu 16.04 build agent.

I should also note that I tried performing the XSL transform via PowerShell with no success.

Upvotes: 0

Views: 1263

Answers (1)

Colin Laws
Colin Laws

Reputation: 680

You are able to download the Java version of Saxon 9 HE as a JAR and run that JAR in VSTS (Azure DevOps). I am running on a hosted Ubuntu 16.04 build agent (which comes with Java, PHP, etc. installed already).

I executed the jar simply by executing the java binary and passing my JAR in the same location as my XML and XSL file:

java -jar saxon9he.jar -xsl:phpunit_to_junit.xsl -s:test-results.xml

This generated a folder that contained my tests, properly formatted for VSTS (Azure DevOps) to consume. Your set up will differ, as all of my tests have '-Test.xml', check out the testResultsFiles option.

I set up my tests to output with the '-Test.xml' by modifying the following line in the XSL.

<xsl:variable name="filename" select="concat('TEST-',@name,'-Test.xml')" />

The next step was to publish my tests using the PublishTestResults task. This is what my YAML file contains for publishing the results.

- task: PublishTestResults@2
  displayName: 'Publish test results'
  inputs:
    testRunner: 'JUnit'
    testResultsFiles: '**/*-Test.xml' 
    searchFolder: '$(System.DefaultWorkingDirectory)'
    mergeTestResults: false

Upvotes: 2

Related Questions