How do i fail a build on pipelines if my tests fail

Hi all,


I have a dotnet core app i am trying to run tests against, to discover my tests i am running the find command in bash. When doing this if the tests fail, the build still passes. Does anyone have any ideas on how to get it failing or any workarounds




1 answer

I Solved the issue. if anyone else is having the same issue you can use or do do something similar to this


image: microsoft/dotnet:onbuild
    - step:
        script: # Modify the commands below to build your repository.
          - dotnet restore
          - dotnet build *\\**\\project.json
          - chmod u+x
          - ./

 then create a build script containing

TESTS=`find "tests" -name 'project.json'`
for FILE in $TESTS; do
COMMAND="dotnet test $FILE" 

this will find any project that contains the word tests and runs dotnet test against the project. if the tests fail the build will fail, if the tests pass the build will pass. its pretty dumb search atm but works for me. tweak to your needs

Nice job! smile

I'm just going to add some additional information for anyone looking into a similar problem: Pipelines determines the status of your build by reading the exit code of your bash commands. The find command here had wrapped the execution of the dotnet tests, but didn't seem to be propagating the exit code from the tests. Instead it was returning that it successfully completed the "find". The solution here (and in other similar problems) will be to try and find a way to ensure that Pipelines can see the exit codes of your commands.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

30,938 views 26 12
Join discussion

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