djkjlz
djkjlz

Reputation: 55

Import cucumber results to Jira/Xray due the curl

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

Upvotes: 1

Views: 1304

Answers (1)

Sérgio
Sérgio

Reputation: 2129

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

Upvotes: 2

Related Questions