簡體   English   中英

紐曼與 AzureDevOps + Powershell

[英]Newman with AzureDevOps + Powershell

大家,早安

我正在嘗試將 postman 測試與 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 中遇到真正的錯誤或有過新人測試的經驗?

當您在 VSTS 中運行上述腳本時,請刪除newman run行中的$()

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

然后腳本可以非常成功地運行。

我想你已經知道,對於 powershell 命令行,即使newman run命令已經運行成功,在 powershell 命令行界面中也不會顯示任何結果。 因此,日志中不會直接顯示任何消息讓您知道它是否成功。 要在 VSTS 中確認這一點,如果您使用的是私有代理,您可以檢查代理緩存:

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM