[英]Import automated test results to Xray Cloud multipart using Azure Devops
I am trying to import results to Xray Cloud multipart using Azure Devops, this is my bash command from the yml configuration file:我正在尝试使用 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"
I am receiving this error everytime in the pipeline console:我每次在管道控制台中都会收到此错误:
"curl: (26) Failed to open/read local data from file/application
##[error]Bash exited with code '26'."
What am I doing wrong?我究竟做错了什么?
The bash log: 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
==============================================================================
If you used the commands exactly as you shared then you must have a file named "path\issueFields.json".如果您完全按照您共享的方式使用命令,那么您必须有一个名为“path\issueFields.json”的文件。 I guess that "path" is not a real directory name.
我猜“路径”不是真正的目录名。 The same applies to other files you identify.
这同样适用于您识别的其他文件。 So probably your curl command should be just something like:
所以可能你的 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"
One more way of achieving this is by automating the XRay API in PowerShell.实现此目的的另一种方法是在 PowerShell 中自动化 XRay API。
Here's how to achieve this:以下是如何实现这一点:
$Body = @{ client_id = "" client_secret = "" }
$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" }
$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
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$token = Invoke-RestMethod @Parameters
$token = Invoke-RestMethod @Parameters
$Header = @{ "Authorization" = "Bearer $token" }
$Header = @{ "授权" = "承载 $token" }
$FileContent = [IO.File]::ReadAllText('$(System.DefaultWorkingDirectory)\EnterYourResultFilePath');
$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 Headers = $Header ContentType = "application/xml" }
$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
I use this script to upload results to JIRA from an XML file.我使用此脚本将结果从 XML 文件上传到 JIRA。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.