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

jordan-Anderson October 15, 2016

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

2 votes
jordan-Anderson October 15, 2016

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

Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 16, 2016

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
TAGS
AUG Leaders

Atlassian Community Events