0

I am using Jira cloud and trying to import the Xunit json report (result.json) generated by cucumber to Jira with Xray using Jira rest API, I've tried various ways to import the reports from command line but so far no luck.

Ex:

curl -H "Content-Type: application/json" -X POST -u ID:token -F "file=D:\Report.json" "https://raheel.atlassian.net/api/v2/import/execution"
curl -H "Content-Type: application/json" -X POST -u  user:token --data @"D:\Report.json" "https://raheel.atlassian.net/rest/api/3/issue/DEM-9"
curl -H "Content-Type: application/json" -X POST -u  user:token --data @"D:\Report.json" "https://raheel.atlassian.net/rest/raven/2.0/api/Test Execution/DEM-12"

**Error:**

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><status><status-code>404</status-code><message>null for uri: https://raheel.atlassian.net/rest/raven/2.0/api/Test%20Execution/DEM-12</message></status>
token=$(curl -H "Content-Type: application/json" -X POST --data @"{ "client_id": "ID","client_secret": "secret" }" https://xray.cloud.xpand-it.com/api/v2/authenticate| tr -d '"') curl -H "Content-Type: application/json" -X POST -H "Authorization: Bearer $token"  --data @"D:\Report.json" https://xray.cloud.xpand-it.com/api/v2/import/execution/cucumber
Atif
  • 59
  • 6

1 Answers1

2

First of all, it seems that you are using Xray Cloud (i.e. Xray for Jira Cloud). The proper documentation for Xray Cloud's REST API can be found here.

First, you need to create an API key (pair of client id and client secret) on Xray settings. Then you need to authenticate in order to obtain a token that you'll need to provide in all following requests.

The following example, shows a way of setting a shell variable with the token value, so it can be used in subsequent requests

token=$(curl -H "Content-Type: application/json" -X POST --data @"cloud_auth.json" https://xray.cloud.xpand-it.com/api/v2/authenticate| tr -d '"')

Then you can invoke the REST API endpoint to submit the Cucumber JSON report.

curl -H "Content-Type: application/json" -X POST -H "Authorization: Bearer $token"  --data @"Report.json" https://xray.cloud.xpand-it.com/api/v2/import/execution/cucumber

Please note that in order to import Cucumber related results using a cucumber JSON report, your Scenarios need to be properly tagged. You need to follow one of the flows detailed here.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Sérgio
  • 1,777
  • 2
  • 10
  • 12
  • It worked thanks a lot. But it's creating a new Jira ticket, is it possible to import the report in existing ticket or to any specific ticket number? – Atif Jul 19 '21 at 14:01
  • 1
    Reporting to an existing Test Execution issue (I guess you mean that), requires that your results are tagged with it, namelly the Feature. If you originally exported/generated the feature, by exporting it from an existing Test Execution issue containing some Cucumber test scenarios, then it will contain the tag automatically. Btw: can I please ask you to mark the answer as correct? :) thanks! – Sérgio Jul 19 '21 at 14:19