How to get Xray Test related to Test Execution with scriptrunner in Jira cloud

thibaud.norguet-sc April 14, 2023

Hi,

I'm on Jira Cloud and I want to autofill a custom field on a Test execution: when a Test Execution is created on a Test page, set custom field value on Test execution inherit from with the value of the custom field on Test.

On Jira Data Center, I used Scriptrunner and the custom field “Tests association with a Test Execution” to get the issue key of the Test, and then get the value of the custom field.

In cloud version, the “Test association with a Test Execution” custom field does not exist anymore.

 

I read about Xray REST API and GraphQL but I don't know how to use it with scriptrunner (authenticattion, call, and so on)

I tried also with Jira Cloud Automation but I don't know what conditions to choose to link Test Execution and Test.

 

Do you know how can I autofill a custom field of a Xray Test Execution from the Test custom field value on Jira Cloud ?

 

Thank you.

2 answers

1 accepted

0 votes
Answer accepted
thibaud.norguet-sc April 18, 2023

Hi,

I found a solution using Xray GraphQL API.

As GraphQL have a specific format, I used an online tool to convert the GraphQL query (found on Xray documentation) to convert it to a JSON body for the POST request.

 

import groovy.json.*

// get Xray API token using Xray REST API
def idclient = JsonOutput.toJson([client_id: "my_xray_api_id", client_secret: "my_xray_api_secret"])
def getToken = post('https://xray.cloud.getxray.app/api/v2/authenticate').header('Content-Type', 'application/json').body(idclient).asObject(Map)
def apiToken = getToken.headers['x-access-token'][0]

// get Test Execution key
def issueKey = issue.key


// GraphQL query in JSON body format
def msg = [ "query":"{ getTestExecutions(jql: \"key = ${issueKey}\", limit: 10) { results { tests(limit: 10) { results { jira(fields: [\"key\"]) } } } }}" ]

// call GraphQL API function
def result = post('https://xray.cloud.getxray.app/api/v2/graphql')
.header('Content-Type', 'application/json')
.header('Authorization', "Bearer ${apiToken}")
.body(msg)
.asObject(Map)

if(result.status == 200){

// rest of my code

}
0 votes
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 17, 2023

Hi @thibaud.norguet-sc - welcome to the community,

As I mainly try to solve things with A4J in cloud and the only experience I have with scriptrunner is on Server/DC I´m wondering how this could be done here.

The action itself (test is added to test execution) is an xray specific action --> means jira native, therefore A4J could not grab this event with a trigger.

How did you grab the event on Server in your scriptrunner solution?

Best
Stefan

thibaud.norguet-sc April 18, 2023

Hi @Stefan Salzl 

Thank you for your reply

The main purpose is to facilitate Test Execution creation for end user.

So the trigger is not when a test is added to a Test Execution, but when a Test execution is created from an existing Test, so Test Execution inherit values from the Test and user don't have to fill the field manually.

 

On Server/DC, I created a post function on Test Execution workflow : when a Test Execution is created, the scriptrunner script is run to get and set the values.

 

I finally found a solution for my issue using Xray GraphQL API (this is the only way to get Xray datas in Cloud, a lot of Xray custom fields disappeared from Server/CD to Cloud).

 

Best.

Like Stefan Salzl likes this
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 18, 2023

Hi @thibaud.norguet-sc 

good to know you found a solution.

Would you be so kind to post you solution here to share with other users that might be faced with similar problems?

You could post it as an answer to your own question and then mark it as accepted with the accept button. This will mark the question as solved and help other users finding appropriate solutions.

Best
Stefan

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events