简体   繁体   中英

Newman with AzureDevOps + Powershell

Good morning everyone

I am trying integrate postman tests with AzureDevops Release pipeline. I have two steps:

  • First step is to install newman
  • Second step is to run collection scripts with newman run comand

The second step looks like:

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 $_
}

Above step do not work as expected. In the release log I can see the both messages like:

   Write-Host running $collection
   Write-Host will create $resultFile

However the line

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

is not being executed.

I did the same on my local machine and the command is working. However the bad thing is the try catch block is not working and only I can see as the result is:

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.

Do anyone know how to get real error or had experience with newman testing in AzureDevOps?

When you run those above scripts in VSTS, please remove $() in the newman run line:

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

Then the script can be run very successfully.

I think you have known that for powershell command line, there will no result displayed in the powershell command line interface in the even if the newman run command has been ran succeed. So, there will no any directly message displayed in the log to let you know whether it is succeed. To confirm this in VSTS, you could check the agent cache if you are using private agent:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM