【问题标题】:Newman with AzureDevOps + Powershell纽曼与 AzureDevOps + Powershell
【发布时间】: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


【解决方案1】:

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

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

那么脚本就可以非常成功的运行了。

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

【讨论】:

    猜你喜欢
    • 2019-04-13
    • 2020-12-14
    • 2020-08-17
    • 2022-01-23
    • 2019-04-08
    • 2011-04-01
    • 2018-04-18
    • 2019-08-04
    • 2018-03-11
    相关资源
    最近更新 更多