Created
October 6, 2017 21:37
-
-
Save thadguidry/ccb8dce6bc363dbc17a810d7198661be to your computer and use it in GitHub Desktop.
Jenkins Pipeline Groovy snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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