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

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

Avatar

1 badge earned

Collect

Participate in fun challenges

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

Challenges
Coins

Gift kudos to your peers

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

Recognition
Ribbon

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!

Leaderboard

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
4,556,612
Community Members
 
Community Events
184
Community Groups

How to Call Internal Jira Rest URL with scriptrunner

Krishnanand Nayak
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Feb 22, 2019

We are trying to implement this solution as part of a listener. This example need me to save the user/password, but we want to use the logged in user when making the call to the rest url. So 2 questions:

  1. When i call a internal rest url in a listener, do i need to authenticate the user?
  2. if yes, how do i use the current logged in user details to authenticate?

 

boolean associateTestsToTestExecution(testExecKey,listOfTestKeys){
def jiraBaseUrl = com.atlassian.jira.component.ComponentAccessor.getApplicationProperties().getString("jira.baseurl")
def endpointUrl = "${jiraBaseUrl}/rest/raven/1.0/api/testexec/${testExecKey}/test"
url = new URL(endpointUrl);
def body_req = [ "add": listOfTestKeys ]

// you should use a specific user for this purpose
username = "admin"
password = "admin"
def authString = "${username}:${password}".bytes.encodeBase64().toString()

URLConnection connection = url.openConnection();
connection.requestMethod = "POST"
connection.doOutput = true
connection.addRequestProperty("Authorization", "Basic ${authString}")
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8")
connection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, body_req) }
connection.connect();
log.debug(connection.getResponseCode())
log.debug(connection.getResponseMessage())

if (connection.getResponseCode() == 200) {
// OK
return true;
} else {
// error
return false;
}
}

 

1 answer

0 votes
Katy Kelly
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Mar 28, 2019

Hi Krishnanand, 

So that others can benefit from the answer we supplied in your support ticket we are also listing it here: 

As you can see from the example, the XRay team is using hardcoded credentials to interact with the REST API.
They are doing this because for security reason Atlassian does not allow you to get the password from the logged user.

Usually, when interacting with other plugins from Jira you don't need to make a REST call, the plugin exposes some Java API what can be used with the @WithPlugin annotation directly inside the script as explained here . 
Unfortunately, I was not able to find any Java API exposed from XRay.

If XRay needs to get notified by this and there is no Java API available, the only way to achieve this is through the REST API.

If the tracking needs to be done on the Jira side, then we can come up with something to track who is clicking the button. 
If the tracking needs to be done on the XRay side, then there is not much you can do.

We would appreciate if you can accept the answer so that others know about this. 

Regards,

Katy

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events