53

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..."
...
Vojtech B
  • 2,837
  • 7
  • 31
  • 59

2 Answers2

88

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

If a pipeline job exits with the code other than 0 then that job fails causing all the following jobs in the pipeline to be skipped.

This behaviour can be changed on a per job basis with allow_failure job keyword.

To make a job to fail forcefully you need to artificially exit from a job with code other than 0. Here is an gitlab-ci.yml job example :

some-example-job:
  script:
    - # ....
    - exit 1

enter image description here

See the GitLab CI UI sreeenshot example. The third job has failed.

enter image description here

On the opposite remove exit 0 and your job would succeed if the remaining script section commands do not exit with code other than 0.

Now see all the jobs & the entire pipeline finished successfully. enter image description here

enter image description here

Valentine Shi
  • 6,604
  • 4
  • 46
  • 46
Ala Eddine JEBALI
  • 7,033
  • 6
  • 46
  • 65
2

Your StatusTest.exe has to return a signal 1,0,-1 as status code. It must be implemented in your application. Otherwise the runner will not notify if your application fails. Almost every programming language has ways to return status codes.

C#

Java

System.exit(exitCode) # exitCode = 1 or 0 or -1

[...] and so on.

Maybe try to not throw an exception, just return a status code.

Community
  • 1
  • 1
Rubinum
  • 547
  • 3
  • 18