npm - 在 azure devops 管道中,由于测试结果不成功,强制 newman 任务失败
问题描述
我在 Azure DevOps 管道 YAML 中有一个简单的脚本,使用 newman 执行邮递员收集测试。
- script: $(Agent.WorkFolder)/node_modules/newman/bin/newman.js run "$(Build.SourcesDirectory)/postman/a.postman_collection.json" -e "$(Build.SourcesDirectory)/postman/b.postman_environment.json" -x -r junit --reporter-junit-export $(Build.ArtifactStagingDirectory)/PostmanResults/JunitResults.xml
displayName: Run Postman tests
基本上,它有效。但是无论测试是否通过,这一步总是绿色的。
如果有一些不成功的测试,我怎么能强制这个任务/阶段失败?或者以某种方式确定是否存在测试失败?有谁知道任何聪明的解决方法?
解决方案
您必须捕获退出代码并将其作为写入错误抛出:
尝试类似:
if ($exitCode -ne 0)
{
Write-Output ("[Error] Failing task since return code was {0} while expected 0." -f $exitCode)
Write-Error "##vso[task.complete result=Failed;]Failed"
}
推荐阅读
- ruby-on-rails - 如何在 Rails 中手动创建新的多对多条目
- python-3.x - 对随机生成的字符执行模式搜索时出错:
- javascript - 让`for`循环等待每个函数解析
- haskell - 如何使用`foldTree`实现`zipTree`?
- javascript - 创建了一个脚本来输出可能的口袋妖怪起始元素替代品(火 -> 草 -> 水)。以蛮力成功,如何高效?
- ansible - 如何在 ansible playbook 中捕获 UNREACHBALE HOSTS 消息
- acumatica - Acumatica 将数据从外部 REST 服务加载到网格
- linux - 如何重新配置项目
- ruby - ruby 嵌套 for 循环
- javascript - 什么时候我们不应该在 javascript 中调用 parseint?