Jenkins build gets failed, when unit test cases are failed

802 Views Asked by At

Jenkins build gets failed, when unit test cases are failed, Here am using pipeline script in jenkins, Need to generate HTML report using mocha-awesome, I can get the HTML report only when all test cases are passed, Build fails if any functions failed in my testcases.Here you can see the screenshot

1

There are 1 best solutions below

0
On

The call to the unit test run returns with exit status 1. What you can do is use the returnStatus option for the sh or bat step which will then not fail the build itself but leaves that up to you:

def exitStatus = sh returnStatus: true, script: 'unittests'

or:

def exitStatus = bat returnStatus: true, script: 'unittests.exe'

Having this you can selectively fail the build, i.e. if exitStatus == 1 then ignore as it signals a test fail, if it is anything but 0 or 1 then fail the build using the error step.