r - 发生 R linting 问题时如何使 azure devops 构建失败
问题描述
我在 R 中使用 lintr 库来查找代码中的 linting 问题。我把它们变成这样的xml格式:
<lintsuites>
<lintissue filename="/home/.../blah.R" line_number="36" column_number="1" type="style" message="Trailing blank lines are superfluous."/>
<lintissue filename="/home/.../blahblah.R" line_number="1" column_number="8" type="style" message="Only use double-quotes."/>
</lintsuites>
现在,当出现此类问题时,我想使 Azure devops 构建失败。
我能够以这样的 JUnit 格式进行测试:
<testsuite name="MB Unit Tests" timestamp="2020-01-22 22:34:07" hostname="0000" tests="29" skipped="0" failures="0" errors="0" time="0.05">
<testcase time="0.01" classname="1_Unit_Tests" name="1_calculates_correctly"/>
<testcase time="0.01" classname="1_Unit_Tests" name="2_absorbed_correctly"/>
...
</testsuite>
当我在 azure 管道中执行此步骤时,如果测试套件中的任何测试失败,我的构建将失败:
- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testResultsFiles: '**/*.xml'
searchFolder: '$(System.DefaultWorkingDirectory)/fe'
mergeTestResults: true
failTaskOnFailedTests: true
当出现 linting 问题时,我想要类似的东西来使构建失败。我还希望用户查看构建输出中的这些 linting 问题。谢谢
解决方案
这对于 lintr xml 和plishTestResults@2
.
您可以尝试的解决方法是使用 powershell 任务来检查 lintr xml 文件的内容。如果内容不为空,则使 powershell 任务中的管道失败。
下面的 powershell 任务将检查 lintr.xml( <car></car>
) 的内容,并将内容回显到任务日志,exit 1
如果内容为空,则任务失败。
- powershell: |
[xml]$XmlDocument = Get-Content -Path "$(system.defaultworkingdirectory)/lintr.xml"
if($XmlDocument.OuterXml){
echo $XmlDocument.OuterXml
}else{exit 1}
displayName: lintr result.
您也可以在 powershell 任务中使用以下语句将 lintr xml 文件上传到可以下载的构建摘要页面
echo "##vso[task.uploadsummary]$(system.defaultworkingdirectory)/lintr.xml"
您可以在此处查看更多日志记录命令。
更新:
以一种很好的方式显示 lintr 结果的解决方法是创建一个自定义扩展以在 azure devops 管道中显示 html 结果。
您可以尝试创建自定义扩展,并生成 html lint 结果。请参阅此线程的答案示例自定义扩展以显示 html
其他开发人员已经向 Microsoft 提交了实现此功能的请求。请在这里投票或创建一个新的。
推荐阅读
- android - 为什么我在带有 Kotlin 的 Android Studio 中使用 async{} 后会得到 LiveData 的 null 值?
- html - 在 vb.net 中的 HTML5 类型周如何获取值?
- android - 将 MutableLiveData 传递给其他 ViewModel 是否有效?
- android - Xamarin Forms Icons 出于某种原因转向我认为汉字
- assembly - 在 SysV ABI 中的 edi/esi 中传递参数
- android - audioserver 错误阻止 android ROM 启动
- python - Ansible 基本动态清单
- java - 如何解决具有地图而不是有效的json错误请求的Java resttemplate帖子错误400
- java - 在firebase实时数据库中创建相同的节点
- java - SLF4J:未找到 SLF4J 提供程序