Jenkins junit results coming empty - jenkins

I am using jenkins Jenkins 2.277.4 and junit plugin 1.51
My jenkinsfile code has below snippet for junit
junit allowEmptyResults: true, testResults: "${COMPONENT}/*_test_report.xml"
I have check the file ${COMPONENT}/*_test_report.xml and it is non empty.
but I am getting results in pipeline as
Recording test results
[Checks API] No suitable checks publisher found.
I have tried upgrading the plugin , not sure what is wrong I am doing here ?

From the https://plugins.jenkins.io/junit/ docs, use the skipPublishingChecks: true argument to disable publishing warnings back to your SCM provider.

Related

NUnit-report does not mark build as error

Within my freestyle Jenkins-job I´m executing unit-tests via the "execute Windows batch-command"-step:
call "C:\Program Files (x86)\NUnit.org\nunit-console\nunit3-console.exe" MyAssembly.dll
call SomeOtherProcess
As there are tests that fail, I´d expected the build to fail as well. However the test-publishing-step for NUnit markes the build as unstable:
Build step 'Publish NUnit test result report' changed build result to UNSTABLE
If I´d remove the SomeOtherProcess-line from my batch-script, everything works fine and the errors produced by nunit are reported as error in the build-process.
I read a similar issue for the JUnit-test-reporter (Jenkins JUnit Plugin reports a build as unstable even if test fails). Obviously that reporter does not even support failing the build. I´m not sure if the same applies to the NUnit-reporter as well.
The plugin set the result to UNSTABLE because the option, by default, failedTestsFailBuild is set to false.
You can control the behavior applies of NUnit, setting failedTestsFailBuild to true. When you call from a scripted or declarative pipeline.
The issue is the GUI doesn't reflect all the options available for this plugin. There is a PR opened to include this option inside the freestyle pipeline, you can vote up or ask the status of this PR.
To change to an error you need to catch the unstable result and set it to failure using a plugin or a scripted or declarative pipeline.

How to Publish Jacoco Report in Jenkins Using Jenkins Declarative Pipeline Statage

Can you please any one tell me how can publish the Jacoco Report in Jenkins.
I mean after the pipeline execution done the test report need to show on the jenkins dhash Borad.
You should use jacoco step available with Jacoco plugin
jacoco classPattern: "**/classes", sourcePattern: "**/src/main/java"
https://jenkins.io/doc/pipeline/steps/jacoco/#-jacoco-record-jacoco-coverage-report
You can play around with this on the Snippet Generator available at https://<yourJenkins>/pipeline-syntax/

No such DSL method 'junit'

I don't even know where to begin. JUnit plugin is installed and is running in some scripts (I couldn't find those, it's a large project, but the statistic page indicates 28 usages). But, the pipeline code junit "foo.xml" fails with
java.lang.NoSuchMethodError: No such DSL method 'junit' found among steps
Followed by 100,500 lines of usual nonsense.
Is there anything special I need to do to "enable" this plugin? Jenkins wiki lists it as "required" (whatever that means). The example Jenkinfile that illustrates the usage of this plugin never imports anything. Nonexistent debugging and ninja-style documentation don't really help getting to the culprit of this problem.
When I tried to replace junit 'foo.xml' with step([$class: 'JUnitResultArchiver', testResults: './foo.xml']). This "step" produced the following output:
Recording test results
And failed the build without any further messages. Neither in console nor in the logs collected by the pipeline.

How can I publish NUnit test results using Jenkins Pipeline?

Trying to use the nifty Jenkins Pipeline, I had problems finding out how to publish NUnit test results.
I am able to run the tests by specifying the following command in the pipeline script:
stage 'Test'
bat '"C:\\Program Files (x86)\\NUnit 2.6.4\\bin\\nunit-console-x86.exe" "ProjectName\\bin\\Release\\UnitTests.net.dll"'
But how to make Jenkins "publish" the test results is not obvious. The Snippet Generator only suggests junit, and that does not seem to work.
I used nunit plugin version 0.21 and was able to publish results using
stage("PublishTestReport"){
nunit testResultsPattern: 'TestResult.xml'
}
(TestResult.xml is at the root of jenkins workspace in this above example)
Investigating the NUnit plugin for Jenkins led me on to this issue, where I found the solution:
step([$class: 'NUnitPublisher', testResultsPattern: 'TestResult.xml', debug: false,
keepJUnitReports: true, skipJUnitArchiver:false, failIfNoResults: true])
Adding this to the pipeline script worked for me!
However, it seemed the following should also work (but at the present, apparently, it does not): Using the Snippet Generator, select this:
step: General Build Step
Publish NUnit test result report
This generates the following in the Pipeline script:
step <object of type hudson.plugins.nunit.NUnitPublisher>
This fails!

Using the features provided by a plugin in a Jenkins workflow/pipeline

I have a jenkins standalone job, that uses the MSTest plugin, it publishes the test result (.trx) on the jenkins UI. I want to use this feature of the plugin via the workflow script. How can i achieve this?
At the moment, i am using this batch file, but it need the extra utilities like the "msxls.exe" which doesn't comes with cloudbees jenkins out of the box.
stage name: 'Publish test result', concurrency: 1
bat 'C:\\bin\\msxsl.exe TestResult.trx "C:\\Jenkins\\plugins\\mstest\\WEB-INF\\mstest-to-junit_withOutput.xsl" -o JUnitLikeResultsOutputFile1.xml'
step([$class: 'JUnitResultArchiver', allowEmptyResults: true, testResults: 'JUnitLikeResultsOutputFile1.xml'])
If a plugin is compatible with the Pipeline plugin, then you can find out the appropriate Groovy DSL for it by enabling the "Snippet generator", choosing "step" and finding the desired build step in the "Build step" list.
It would look somewhat similar to the JUnitResultArchiver step you're already using.
However, unfortunately, the MSTest Plugin is not currently compatible with the Pipeline plugin, so it's not available in this list.
You would have to file a feature request to get this implemented.
The Pipeline plugin documentation also has some documentation for developers on how to make plugins compatible.

Resources