![](/img/trans.png)
[英]How to add test results in Azure DevOps through REST API java?
[英]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。
以下是如何實現這一點:
$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.