Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

274
Visualizações
How to mark stage as unstable if Powershell condition results into true?

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?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I tried to add an additional stage code-quality which works perfectly fine for me

image: mcr.microsoft.com/dotnet/sdk:5.0

stages:
  - build
  - code-quality
  - unit-tests

build:
  stage: build
  script:
    - dotnet build --output build
  artifacts:
    paths:
      - build

code-quality:
  stage: code-quality
  script:
    - |-
      dotnet tool install -g dotnet-format;
      dotnet format -wsa --check --verbosity diagnostic;

      if ($LASTEXITCODE) 
      {
        exit 1;
      }
  allow_failure: true
  dependencies:
    - build

unit-tests:
  stage: unit-tests
  script:
    - dotnet test --no-build --output build
  dependencies:
    - build

The only thing I'm wondering about is why I have to check for the exit code. If dotnet format fails it exits with the code 2. But Gitlab seems to check for the exit code 0 or 1 only? Because the error code 2 results into success. That's why I have to check for it manually.

If someone knows how to improve this please let me know!

over 4 years ago · Santiago Trujillo Relatório

0

Not quite sure if this would be what you are looking for but my understanding is that your unit-tests depends on the previous code-quality or build step (or both)? In this case you modify your unit-tests step to be something like:

unit-tests:
  stage: unit-tests
  script:
    - dotnet test --no-build --output build
  # replace 'dependencies' with 'needs'
  needs:
    - job: build
      artifacts: true
    - job: code-quality

The consequences would be that if the build fails your pipeline will fail, in case the code-quality step fails it will still be able to run the unit-tests, except when the test step would depend on artifacts from code quality step

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda