【发布时间】:2020-03-18 16:49:39
【问题描述】:
大家早上好
我正在尝试将邮递员测试与 AzureDevops 发布管道集成。 我有两个步骤:
- 第一步是安装newman
- 第二步是使用 newman run 命令运行收集脚本
第二步是这样的:
try
{
$testFiles = Get-ChildItem *.postman_collection.json -Recurse
$environmentFile = Get-ChildItem *staging.postman_environment.json -Recurse
Write-Host $testFiles.Count files to test
foreach ($f in $testFiles)
{
$environment = $environmentFile[0].FullName
Write-Host running file $f.FullName
Write-Host usting environment $environment
$collection = $f.FullName
$resultFile = "Results\" + $f.BaseName + ".xml"
Write-Host running $collection
Write-Host will create $resultFile
$(newman run $collection -e $environment -r junit --reporter-junit-export $resultFile)
}
}
catch
{
Write-Host "Exception occured"
Write-Host $_
}
上述步骤未按预期工作。在发布日志中,我可以看到两条消息,例如:
Write-Host running $collection
Write-Host will create $resultFile
然而行
$(newman run $collection -e $environment -r junit --reporter-junit-export $resultFile)
没有被执行。
我在我的本地机器上做了同样的事情,并且命令正在运行。但是不好的是 try catch 块不起作用,只有我能看到结果是:
2019-11-22T15:11:23.8332717Z ##[error]PowerShell exited with code '1'.
2019-11-22T15:11:23.8341270Z ##[debug]Processed: ##vso[task.logissue type=error]PowerShell exited with code '1'.
2019-11-22T15:11:23.8390876Z ##[debug]Processed: ##vso[task.complete result=Failed]Error detected
2019-11-22T15:11:23.8414283Z ##[debug]Leaving D:\a\_tasks\PowerShell_e213ff0f-5d5c-4791-802d-52ea3e7be1f1\2.151.2\powershell.ps1.
有谁知道如何在 AzureDevOps 中遇到真正的错误或有过新人测试的经验?
【问题讨论】:
-
尝试在您的
newman命令之前添加这一行: $ErrorActionPreference = 'Stop' 它不会解决问题,但它应该可以帮助您正确捕获错误。 -
只是想检查一下你现在在VSTS中运行上面的脚本是否成功?如果对该建议或以下建议仍有疑问,请随时在下面发表评论:-)
标签: powershell azure-devops postman newman