简体   繁体   English

纽曼与 AzureDevOps + Powershell

[英]Newman with AzureDevOps + Powershell

Good morning everyone大家,早安

I am trying integrate postman tests with AzureDevops Release pipeline.我正在尝试将 postman 测试与 AzureDevops 发布管道集成。 I have two steps:我有两个步骤:

  • First step is to install newman第一步是安装newman
  • Second step is to run collection scripts with newman run comand第二步是使用newman run命令运行收集脚本

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:然而,不好的是 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.

Do anyone know how to get real error or had experience with newman testing in AzureDevOps?有谁知道如何在 AzureDevOps 中遇到真正的错误或有过新人测试的经验?

When you run those above scripts in VSTS, please remove $() in the newman run line:当您在 VSTS 中运行上述脚本时,请删除newman run行中的$()

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.我想你已经知道,对于 powershell 命令行,即使newman run命令已经运行成功,在 powershell 命令行界面中也不会显示任何结果。 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:要在 VSTS 中确认这一点,如果您使用的是私有代理,您可以检查代理缓存:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AzureDevops PowerShell和任务 - AzureDevops PowerShell and Tasks 如何在 Powershell 中使用 RestApi 从 AzureDevOps 获取工作项 - How to get the workitems from AzureDevOps with RestApi in Powershell 如何通过 AWS 工具使用来自 AzureDevops 的 Powershell 7 - How to use Powershell 7 from AzureDevops with AWS Tools AzureDevOps Powershell 任务命令行参数在 Powershell 脚本中未正确呈现 - AzureDevOps Powershell task command line parameters are not properly rendered in Powershell script Powershell Newman run pass --env-var as string - Powershell Newman run pass --env-var as string AzureDevOps:将任务变量作为对象传递给后续的 powershell 任务类型 - AzureDevOps: Pass task variable to subsequent powershell task type as Object nuget(powershell 或 AzureDevOps 任务)中的 .config 文件的令牌替换 - Token replacement of .config files inside a nuget (powershell or AzureDevOps task) 在 Azuredevops 发布管道中使用 powershell 脚本执行 SSIS 作业 - Executing SSIS job using powershell script in Azuredevops release pipeline Powershell脚本任务output的AzureDevOps Pipeline变量赋值 - AzureDevOps Pipeline variable assignment of Powershell script task output AzureDevOps 任务中 Powershell Start-Process 上的访问被拒绝 - Access Denied on Powershell Start-Process within AzureDevOps task
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM