Failing a Bitbucket Pipeline build when returns a low coverage %

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 ( but can't actually find any information on how to do it, would appreciate some understanding on this all.


3 answers

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.

0 votes

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.

@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
  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.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

700 views 5 10
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you