简体   繁体   中英

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:

     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:

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". 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 -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.

Here's how to achieve this:

  1. Add a "PowerShell" task in your Azure Pipeline.
  2. Select "Type" as "Inline".
  3. Enter this script:

$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 = @{ "Authorization" = "Bearer $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 Headers = $Header ContentType = "application/xml" }

 Invoke-RestMethod @Parameters

I use this script to upload results to JIRA from an XML file.

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