How to set jenkins job status based on test case pass %

Hi,

how to set jenkins job status based on test case pass %. My project is based on Selenium and TestNG. planning to integrate with build pipeline. So my build has to pass if the test case pass % is greater than 95%.

Can any one help me how to set this condition in the jenkins job?

Thanks In Advance
Phanindra M

1 Like

Hello. If you use XUnit plugin to publish test results, there is a “threshold” concept that should allow you to adjust scores for tests: https://plugins.jenkins.io/xunit/ . There is no similar feature for the JUnit plugin.

TBH I am not sure this is a great approach to set test threshold. What is the use-case for that? Ignoring some flaky tests? If so, maybe you want to take a look at https://plugins.jenkins.io/flaky-test-handler/

Hi oleg,

Thank a lot for your inputs.

Our is a wrapper application which has many micro application which are owned by different project teams. to check the overall sanity of the wrapper application I’m planning to have the threshold and test it only in dev environment, so that the build which is deployed will not fail for one or two micro app issues.

we are using extent reports. so thought of check if we can set any threshold for the test case pass %.

I will take a look at the plugins which you had specified if those works then i’ll change the reports part.

Thanks,
Phani.

If you post part of your pipeline code I should be able to help, but I think what you are trying to do is pretty straight forward.

int testScore = getTestResult() // this is a made up function

if (testScore < 95) {
    currentBuild.status = 'ABORTED' // I prefer aborted, most people use FAILURE
}

You will just need to figure out how to get the test result from what ever tool/plugin you are running your test with.

Junit plugin exposes the information in the result object so you can script this yourself: