I have a fairly complete build process written in Groovy running under a Pipeline build, including running unit tests and reporting the test results back to Jenkins using JUnitResultArchiver.
Given that Jenkins has parsed that XML for me and has the test results, I would like to extract any and all test cases at the end of the build for inclusion in an email.
Trying to interact with testResultAction I end up with unclassified method errors.
Any help or examples would be appreciated!
The purpose of the pipeline is to assemble several steps that can be cross-validated together while setting different parameters. For this, it enables setting parameters of the various steps using their names and the parameter name separated by a '__' , as in the example below.
Pandas pipeline feature allows us to string together various user-defined Python functions in order to build a pipeline of data processing. There are two ways to create a Pipeline in pandas. By calling . pipe() function and by importing pdpipe package.
Click the New Item menu within Jenkins. Provide a name for your new item (e.g. My-Pipeline) and select Multibranch Pipeline. Click the Add Source button, choose the type of repository you want to use and fill in the details. Click the Save button and watch your first Pipeline run.
Different Types of Jenkins CI/CD Pipelines. Scripted Pipeline. Declarative Pipeline.
Ended up getting this sorted out. Here's the function I wrote, feel free to tweak to suit your needs:
@NonCPS
def reportOnTestsForBuild() {
def build = manager.build
println("Build Number: ${build.number}")
if (build.getAction(hudson.tasks.junit.TestResultAction.class) == null) {
println("No tests")
return ("No Tests")
}
// The string that will contain our report.
String emailReport;
emailReport = "URL: ${env.BUILD_URL}\n"
def testResults = build.getAction(hudson.tasks.junit.TestResultAction.class).getFailCount();
def failed = build.getAction(hudson.tasks.junit.TestResultAction.class).getFailedTests()
println("Failed Count: ${testResults}")
println("Failed Tests: ${failed}")
def failures = [:]
def result = build.getAction(hudson.tasks.junit.TestResultAction.class).result
if (result == null) {
emailReport = emailReport + "No test results"
} else if (result.failCount < 1) {
emailReport = emailReport + "No failures"
} else {
emailReport = emailReport + "overall fail count: ${result.failCount}\n\n"
failedTests = result.getFailedTests();
failedTests.each { test ->
failures.put(test.fullDisplayName, test)
emailReport = emailReport + "\n-------------------------------------------------\n"
emailReport = emailReport + "Failed test: ${test.fullDisplayName}\n" +
"name: ${test.name}\n" +
"age: ${test.age}\n" +
"failCount: ${test.failCount}\n" +
"failedSince: ${test.failedSince}\n" +
"errorDetails: ${test.errorDetails}\n"
}
}
return (emailReport)
}
One way you could do this is by writing Postbuild Groovy Script.
In a postbuild groovy script, you can retrieve all the artifacts from all the builds executed in the pipeline via the jenkins api or filesystem.
Once you have all the information, I would format it nicely into a HTML and inject that into the Email-ext plugin.
So, the steps would be:
**/surefire/**, **/failsafe/**
)C:\Jenkins\Jobs\MyTestJob\builds\xxxx\surefire\test-results.xml
)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With