Skip to content

Instantly share code, notes, and snippets.

@thadguidry
Created October 6, 2017 21:37
Show Gist options
  • Save thadguidry/ccb8dce6bc363dbc17a810d7198661be to your computer and use it in GitHub Desktop.
Save thadguidry/ccb8dce6bc363dbc17a810d7198661be to your computer and use it in GitHub Desktop.
Jenkins Pipeline Groovy snippet
#!groovy
import hudson.tasks.test.*
import hudson.model.Actionable
import groovy.json.*
def getJunitData() {
testResults = withContext(hudson.tasks.test.TestObject)
echo "describe " + testResults.getFullName()
def jsonStr = '';
if (testResults != null) {
def total = testResults.getTotalCount()
def failed = testResults.getFailCount()
def skipped = testResults.getSkipCount()
def passed = testResults.getPassCount()
jsonStr = '{ "total":'+total+', "pass":'+passed+', "fail":'+failed+', "skip":'+skipped+' }'
} else {
jsonStr = '{ "total":0, "pass":0, "fail":0, "skip":0 }'
}
echo "JUnit Test Result Totals: \n" + jsonStr
return jsonStr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment