I have a .Net 5 solution and build the projects with code style analysis. Each violated rule results in a warning. But the build command exits with the code 0.
I created a .gitlab-ci.yml
file that should mark the pipeline as unstable if any build warnings have been thrown.
image: mcr.microsoft.com/dotnet/sdk:5.0
stages:
- build
- unit-tests
build:
stage: build
script:
- |-
dotnet build --output build -consoleloggerparameters:"Summary;Verbosity=normal" -m -p:"WarnLevel=5;EnforceCodeStyleInBuild=true" -t:"clean,build" -fl1 "/flp1:warningsonly";
if ((!$LASTEXITCODE) -and (Get-Content "msbuild1.log"))
{
# >>> mark stage as unstable here <<<
}
artifacts:
paths:
- build
unit-tests:
stage: unit-tests
script:
- dotnet test --no-build --output build
dependencies:
- build
The stage itself passes but I was hoping that it passes with an unstable state (because of the warnings), unfortunately it’s green.
A bad solution would be adding the -warnaserror
flag for the build command and use allow_failure: true
for the stage. This would set the stage into an unstable state but next stages would fail because of the missing build.
So what would be the correct way to check if the build command finished with warnings to mark the stage as unstable?