Azure DevOps显示生成警告



问题背景

我正在处理一个C#项目,该项目正在使用Azure DevOps for CI。当项目推送到Azure时,我有一个正在运行的powershell文件。构建文件的相关部分是:

# $buildTools is the path to MSBuild.exe
# $solution is the path to the project's .sln file
& $buildTools $solution /t:Clean,Build /p:Configuration=Release,Platform=x86
if ($LASTEXITCODE -eq 0) {
Write-Host 'Build completed successfully!'
} else {
Write-Host '##vso[task.logissue type=error;]There were errors during the build of the application'
}

问题

当前,$LASTEXITCODE可以是0 (no errors),也可以是1 (error)。如果退出代码为0,一切正常,Azure显示绿色通行徽章;如果是1,Azure显示红色错误徽章。但是,当构建中存在警告时,它们会显示在日志中,Azure会显示绿色徽章。

目标

我的目标是让Azure在出现警告时显示黄色/橙色警告徽章。这可能吗?怎么可能?非常感谢您抽出时间!

尝试的解决方案

在C#项目属性中,Warning level设置为4;所以我尝试了对powershell脚本的修改,但是没有成功。

& $buildTools $solution 4> 'warning.txt'

使用解决方案更新

感谢D.J.的回答!最终构建线看起来像:

# $warningsFile is a path to a file that will contain all the warnings
& $buildTools $solution /t:Clean,Build /p:Configuration=Release,Platform=x86 /fl1 "/flp1:$warningsFile;warningsonly"

您可以使用这个->https://learn.microsoft.com/en-us/visualstudio/msbuild/obtaining-build-logs-with-msbuild?view=vs-2017#将日志输出保存到多个文件,并将所有警告写入日志文件,然后检查日志文件是否包含任何内容,然后使用se命令将警告写入输出(https://github.com/Microsoft/azure-pipelines-tasks/blob/master/docs/authoring/commands.md)

最新更新