在 azure devops 管道中,强制 newman 任务因不成功的测试结果而失败
Force newman task fail on unsuccessful test results in azure devops pipeline
我在 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
基本上,它有效。但是 无论测试是否通过,这一步总是绿色的。
如果有一些不成功的测试,我如何强制这个 task/stage 失败?或者以某种方式确定是否存在测试失败?有谁知道任何巧妙的解决方法?
我使用“Newman the cli Companion for Postman”扩展而不是脚本,它对我来说效果相当好:
默认情况下,如果有任何测试失败,任务将使您的管道失败。
这是我在 YAML 管道中使用它配置的任务示例:
- task: carlowaklstedt.NewmanPostman.NewmanPostman.NewmanPostman@4
displayname: "Run Newman Tests"
inputs:
collectionFileSource: "$(System.DefaultWorkingDirectory)"
contents: "**/path-to-postman-collection.json"
environment: "**/path-to-environment.json"
pathToNewman: "(Optional) C:\path\to\newman\installation"
ignoreRedirect: false
bail: false
sslInsecure: false
reporters: "htmlextra,junit"
htmlExtraDarkTheme: false
htmlExtraLogs: false
htmlExtraTestPaging: false
您必须捕获退出代码并将其作为写入错误抛出:
试试这样的:
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"
}
我在 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
基本上,它有效。但是 无论测试是否通过,这一步总是绿色的。
如果有一些不成功的测试,我如何强制这个 task/stage 失败?或者以某种方式确定是否存在测试失败?有谁知道任何巧妙的解决方法?
我使用“Newman the cli Companion for Postman”扩展而不是脚本,它对我来说效果相当好:
默认情况下,如果有任何测试失败,任务将使您的管道失败。
这是我在 YAML 管道中使用它配置的任务示例:
- task: carlowaklstedt.NewmanPostman.NewmanPostman.NewmanPostman@4
displayname: "Run Newman Tests"
inputs:
collectionFileSource: "$(System.DefaultWorkingDirectory)"
contents: "**/path-to-postman-collection.json"
environment: "**/path-to-environment.json"
pathToNewman: "(Optional) C:\path\to\newman\installation"
ignoreRedirect: false
bail: false
sslInsecure: false
reporters: "htmlextra,junit"
htmlExtraDarkTheme: false
htmlExtraLogs: false
htmlExtraTestPaging: false
您必须捕获退出代码并将其作为写入错误抛出:
试试这样的:
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"
}