1

For import results I use curl

var util = require('util');
var exec = require('child_process').exec;

var command = 'curl -u username:password -F info=@cypress/support/xray-json/issue-data.json -F result=@cypress/cucumber-json/test-results.json https://project.atlassian.net/rest/raven/1.0/import/execution/cucumber'

child = exec(command, function (error, stdout, stderr) {

    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);

    if (error !== null) {
        console.log('exec error: ' + error);
    }

});

but also receive the error below

enter image description here

djkjlz
  • 45
  • 1
  • 8
  • Are you using Xray on Jira cloud or Xray for Jira server/datacenter? – Sérgio Apr 13 '22 at 16:00
  • Hi @Sérgio, how can I find out if I'm using Xray on Jira cloud or Xray for Jira server? – HuserB1989 May 04 '23 at 21:39
  • You can ask your Jira administrator. Usually cloud domain end up in .atlassian.net but some organizations use custom domains for their cloud solutions. Also usually server/datacenter is hosted locally, so it has an internal domain/URL. – Sérgio May 05 '23 at 13:44

1 Answers1

2

If you're using Xray on Jira Cloud... An example of doing this request with curl in a bash script would be something like:

# the followin URL corresponds Xray Cloud domain that provides multiple endpoints, for authenticating and other operations
BASE_URL=https://xray.cloud.getxray.app
token=$(curl -H "Content-Type: application/json" -X POST --data @"cloud_auth.json" "$BASE_URL/api/v2/authenticate"| tr -d '"')
curl -H "Content-Type: application/json" -X POST -H "Authorization: Bearer $token"  --data @"report.json" "$BASE_URL/api/v2/import/execution/cucumber"

In the previous script, we can see two endpoints being used: one for authentication and another for importing the results:

These endpoints are from Xray cloud itself; not from Jira. They are not Jira instance specific; they don't change.

The cloud_auth.json used above, has contents such as this:

{ "client_id": "DA2258616A594400000000","client_secret": "5bae1aa5b49e5d263781da54ba0000000000000000000" }

You need to obtain the client_id and client_secret from an API key configured in Xray global settings. enter image description here

In general,

Note that the previous endpoint is the "standard", or in other words the most simple one to use. There is also another endpoint, called the multipart. The syntax is different. You may see here one example for it.

You may find more info about the Xray Cloud REST API endpoints here (currently the site seems to having some load).

Sérgio
  • 1,777
  • 2
  • 10
  • 12
  • could you please explain more what is base_url and what data should be in cloud_auth.json – djkjlz Apr 14 '22 at 08:08
  • can i use instead of @"clod_auth.json" credentials username:jira_token ? – djkjlz Apr 14 '22 at 08:25
  • no, you cannot use Jira related authentication. you have to use the credentials and the authentication mechanism from Xray, and not from Jira itself. I will update the answer with feedback of your first question – Sérgio Apr 14 '22 at 08:37
  • I've updated the answer above – Sérgio Apr 14 '22 at 08:44
  • 1
    could you please explain where i can change the title `Execution results [1649934355283]` - now i'm using xray-code-snippets – djkjlz Apr 14 '22 at 12:44
  • You can't, if you use the standard endpoint as shown above. You'll have to use the multipart endpoint instead, which has a different format. You can see here an example where an auxiliary JSON is used to customize via the Summary field: https://github.com/Xray-App/xray-code-snippets/blob/main/use_cases/import_automation_results/js/import_results_cucumber_multipart_axios_cloud.js – Sérgio Apr 14 '22 at 13:25