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

Thanks

Jordan

fail_erm_wut.PNG

1 answer

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

bitbucket-pipelines.yml

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

 then create a build script containing 

Build.sh

#!/bin/bash
TESTS=`find "tests" -name 'project.json'`
for FILE in $TESTS; do
COMMAND="dotnet test $FILE" 
$COMMAND
done

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 Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

631 views 0 4
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot