繁体   English   中英

使用 Azure Devops 将自动化测试结果导入 Xray Cloud multipart

[英]Import automated test results to Xray Cloud multipart using Azure Devops

我正在尝试使用 Azure Devops 将结果导入 Xray Cloud multipart,这是来自 yml 配置文件的 bash 命令:

     token=$(curl -H "Content-Type: application/json" -X POST --data '{ "client_id": "$(client_id)","client_secret": "$(client_secret)" }' https://xray.cloud.xpand-it.com/api/v1/authenticate| tr -d '"')
     curl -H "Content-Type: multipart/form-data" -X POST -F info=@path\issueFields.json -F results=@path\target\surefire-reports\TEST-TestSuite.xml -F testInfo=@path\testIssueFields.json -H "Authorization: Bearer $token" https://xray.cloud.xpand-it.com/api/v1/import/execution/testng/multipart"

我每次在管道控制台中都会收到此错误:

"curl: (26) Failed to open/read local data from file/application
##[error]Bash exited with code '26'."

我究竟做错了什么?

bash 日志:

Starting: Bash
==============================================================================
Task         : Bash
Description  : Run a Bash script on macOS, Linux, or Windows
Version      : 3.189.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/bash
==============================================================================

如果您完全按照您共享的方式使用命令,那么您必须有一个名为“path\issueFields.json”的文件。 我猜“路径”不是真正的目录名。 这同样适用于您识别的其他文件。 所以可能你的 curl 命令应该是这样的:

curl -H "Content-Type: multipart/form-data" -X POST -F info=@issueFields.json -F results=@./target/surefire-reports/TEST-TestSuite.xml -F testInfo=@testIssueFields.json -H "Authorization: Bearer $token" https://xray.cloud.xpand-it.com/api/v1/import/execution/testng/multipart"

实现此目的的另一种方法是在 PowerShell 中自动化 XRay API。

以下是如何实现这一点:

  1. 在 Azure Pipeline 中添加“PowerShell”任务。
  2. 选择“类型”作为“内联”。
  3. 输入这个脚本:

$Body = @{ client_id = "" client_secret = "" }

$Parameters = @{ Method = "POST" Uri = "https://xray.cloud.getxray.app/api/v1/authenticate" Body = $Body ContentType = "application/x-www-form-urlencoded" }

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$token = Invoke-RestMethod @Parameters

$Header = @{ "授权" = "承载 $token" }

$FileContent = [IO.File]::ReadAllText('$(System.DefaultWorkingDirectory)\EnterYourResultFilePath');

$Parameters = @{ Method = "POST" Uri = "https://xray.cloud.getxray.app/api/v1/import/execution/junit?projectKey=ABCD&testPlanKey=ABCD-$(TestPlanKey)" Body = $FileContent标头 = $Header ContentType = "应用程序/xml" }

 Invoke-RestMethod @Parameters

我使用此脚本将结果从 XML 文件上传到 JIRA。

暂无
暂无

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

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