如果Powershell条件结果为真,如何将阶段标记为不稳定?
c#
我有一个 .Net 5 解决方案并使用代码样式分析构建项目。每个违反规则都会导致警告。但是构建命令以代码 0 退出。
我创建了一个.gitlab-ci.yml文件,如果抛出任何构建警告,该文件应该将管道标记为不稳定。
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
阶段本身通过了,但我希望它以不稳定的状态通过(因为警告),不幸的是它是绿色的。
一个糟糕的解决方案是-warnaserror为构建命令添加标志并allow_failure: true用于舞台。这将使阶段进入不稳定状态,但由于缺少构建,下一阶段将失败。
那么检查构建命令是否以警告结束将阶段标记为不稳定的正确方法是什么?