Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

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


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


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('').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('')
.header('Content-Type', 'application/json')
.header('Authorization', "Bearer ${apiToken}")

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.
Apr 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?


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



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


Suggest an answer

Log in or Sign up to answer
Site Admin
AUG Leaders

Atlassian Community Events