纽曼与 AzureDevOps + Powershell

Newman with AzureDevOps + Powershell

大家早上好

我正在尝试将邮递员测试与 AzureDevops 发布管道集成。 我有两个步骤:

第二步看起来像:

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.151.2\powershell.ps1.

有谁知道如何得到真正的错误或有过在 AzureDevOps 中进行 newman 测试的经验吗?

当你在 VSTS 中 运行 以上脚本时,请删除 newman run 行中的 $():

newman run $collection -e $environment -r junit --reporter-junit-export $resultFile 

那么脚本就可以运行很成功了

我想你已经知道,对于powershell命令行,即使newman run命令已经运行成功,powershell命令行界面也不会显示任何结果。因此,日志中不会直接显示任何消息让您知道是否成功。要在 VSTS 中确认这一点,如果您使用的是专用代理,则可以检查代理缓存: