How to fail a build on Gitlab CI shell runner

Vojtech B picture Vojtech B · Apr 14, 2016 · Viewed 22.9k times · Source

I have a Gitlab CI runner running on windows 10:

before_script:
  - "echo off"
  - 'call "%VS120COMNTOOLS%\vsvars32.bat"'
  - echo.
  - set
  - echo.

stages:
  - build

build:
  stage: build
  script:
  - 'StatusTest.exe'
  #- msbuild...

I am trying to fail the build with StatusText.exe (I tried returning status codes -1,0,1; throwing an exception, etc.) But Runner only logs the exception and continues with following steps.

What determines that CI shell runner should fail the build and not proceed to next step?

Output:

...
windows_tracing_logfile=C:\BVTBin\Tests\installpackage\csilogfile.log
$ echo.

$ StatusTest.exe

Unhandled Exception: System.Exception: tralala
   at StatusTest.Program.Main(String[] args)
$ echo "Restoring NuGet Packages..."
...

Answer

Ala Eddine JEBALI picture Ala Eddine JEBALI · Feb 6, 2017

What determines that CI shell runner should fail the build and not proceed to next step?

1) When it should fail

You need to add this line in your gitlab-ci.yml

- # ....
- exit 1

The stage execution result should fail and does not go to the next step:

enter image description here

and then when you look at your stage (in my case the 3rd one) the result will be failed:

enter image description here

2) When it should succeed

You need to add this line in your gitlab-ci.yml

- # ....
- exit 0

The stage execution result should be:

enter image description here

and then when you look at your stage (in my case the 3rd one) the result will be Ok and ready to go to the next stage:

enter image description here