Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fail a build on Gitlab CI shell runner

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..." ... 
like image 566
Vojtech B Avatar asked Apr 14 '16 09:04

Vojtech B


People also ask

What is pipeline failed in GitLab?

It might be a security vulnerability The code in your most recent commit could be vulnerable, or a dependency could be at risk, either of which would trigger a failed security test and thus a failed pipeline.

How do I see GitLab runner logs?

To view them, open the Event Viewer (from the Run menu, type eventvwr. msc or search for “Event Viewer”). Then go to Windows Logs > Application. The Source for Runner logs is gitlab-runner .

How do you check if a GitLab runner is running?

When you execute gitlab-runner commands, you see the mode it is running in: $ gitlab-runner run INFO[0000] Starting multi-runner from /Users/ayufan/. gitlab-runner/config.


2 Answers

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

like image 155
Ala Eddine JEBALI Avatar answered Oct 08 '22 00:10

Ala Eddine JEBALI


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.

like image 27
Rubinum Avatar answered Oct 08 '22 01:10

Rubinum