-->

Why when test fails jenkins still says success?

2019-06-21 06:01发布

问题:

I have a MEAN project. Using Jenkins on an EC2 machine I build this using the following shell script:

npm install && PORT=8888 npm test

mocha returns 2 (number of failing tests) but still jenkins says:

Finished: SUCCESS.

If tests are failing I expect to see

Finished: FAILURE

Do you know why its not working fine?

回答1:

You can:

  1. Use a test runner like Karma, or
  2. Tell Mocha to report in, for example, XUnit format, by passing Mocha the --reporter xunit flag. XUnit closely aligns with JUnit which Jenkins understands, or
  3. Add in a custom reporter — mocha-jenkins-reporter is a decent option.


回答2:

In the end I used a different solution: installed Jenkins Text Finder and if "expected - actual" is found in log (test failed), I let this plugin to mark the build as "Unstable".