Failing a Bitbucket Pipeline build when Coverage.py returns a low coverage %

Louis Willcock January 9, 2018

Hey, I have been tasked with kitting out our Pipeline with the ability to fail a build/PR when test coverage is underneath a specific quota. I have read one of your articles which states this as a recommended practice (https://www.atlassian.com/continuous-delivery/introduction-to-code-coverage) but can't actually find any information on how to do it, would appreciate some understanding on this all.

Thanks.

3 answers

0 votes
Mina Luke August 6, 2018

@Louis Willcock @Mathew Morrison
It took me while but it is now working for NodeJS project. Here is what you need to do:

  1. Use NYC https://github.com/istanbuljs/nyc
  2. prefix your mocha test runner with nyc in package.json file as follow: 
    "test": "nyc mocha"
  3. Set your preferred coverage ratio as an environment variable NYC_CHECK_COVERAGE in the repository settings
  4. run NYC check coverage command in pipelines: 
    nyc check-coverage --lines ${NYC_CHECK_COVERAGE}

After doing this when ever you create a PR that has coverage less than the value set in the environment variable will fail pipelines.
Cheers.

0 votes
Mathew Morrison July 25, 2018

Why has nobody answered this from Atlassian?

I too would like some clarity on this, is there documentation somewhere? Surely someone would have had an experience with this they can share, some tips or a pointer in the right direction.

0 votes
Louis Willcock January 10, 2018

I'd really appreciate an answer on how I can fail my builds if coverage is under certain thresholds. I'm still looking for a way to do this.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events