0

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://learn.microsoft.com/azure/devops/pipelines/tasks/utility/bash
==============================================================================

vladys2019
  • 39
  • 6

2 Answers2

1

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"
Sérgio
  • 1,777
  • 2
  • 10
  • 12
  • Sergio, "path" was the absolute path of the file location. Also I have tried your curl command exactly as it was written by you but I have the same result :( – vladys2019 Aug 25 '21 at 10:35
  • do you have all those files? can you also try replacing / for \ on the path as it seems you're using a windows system? – Sérgio Aug 25 '21 at 11:04
  • yes, the json files are in the root directory and the xml file is in the surefire-reports folder – vladys2019 Aug 25 '21 at 11:08
  • replacing the / for \ didnt work out in the filepaths? – Sérgio Aug 25 '21 at 11:19
  • I have replaced the / for \ but still didn't work – vladys2019 Aug 25 '21 at 11:19
  • maybe there's some problem with your path in terms of characters. Can you try adding the path between "", 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" – Sérgio Aug 25 '21 at 14:45
  • Thank you Sergio for your help. This is what worked: curl -H "Content-Type: multipart/form-data" -X POST -F info=@issueFields.json -F results=@C:/IdeaProjects/MyProject/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. Basically I have added the full path of the xml results + I have replace the \ with / instead and it worked after that, the test results are importing to jira. – vladys2019 Aug 27 '21 at 07:49
1

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.

Jaideep Dhumal
  • 903
  • 6
  • 6