How to get current user in jira application?

Ramesh Lakshmanasamy June 11, 2018

I need to get current user in Jira.but i tried few ways but didn't get a solution.

4 answers

1 accepted

6 votes
Answer accepted
Mark Markov
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.
June 11, 2018

Hello @Ramesh Lakshmanasamy

Did you mean get user in code of some plugins like Scriptrunner?

If you do, you can use

import com.atlassian.jira.component.ComponentAccessor
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

If you write jira plugin
you need to import it directly 

@ComponentImport JiraAuthenticationContext jiraAuthenticationContext
Ramesh Lakshmanasamy June 11, 2018

@Mark MarkovI tried above solution but getting null.

Mark Markov
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.
June 11, 2018

Where are you tryin to get current user?

Ramesh Lakshmanasamy June 11, 2018

inside class which has contain my businesslogic

Mark Markov
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.
June 11, 2018

where you run your class, if you run it in another thread, there are no authentication context so user is null. So you'll need to pass the user as parameter.

Can you provide example of your code?

0 votes
Stan Dalenc August 15, 2023

Does anyone know how to get this using Scriptrunner for Jira Cloud?

Stan Dalenc August 15, 2023

I found 'user' does this so that you can use user.accountId to compare against, but it doesn't seem to work in all contexts like post functions.

0 votes
Inetinfo Inetinfo November 3, 2022

Hi

How can we get " company name" value of current logged user of jira by using script

company.png

0 votes
Ramesh Lakshmanasamy June 13, 2018

Thanks @Mark Markov it's working fine.

Timothy Phan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 27, 2022

How to get the user in a Jira Service that extended from AbstractService and running from Service Scheduler/Cron?

 

ComponentAssessor.getJiraAuthenticationContext().getLoggedInUser()


always return null.

Chamdarig Dall October 1, 2023

just paste this code to the console.

btw this script will just let you know that you are logged in :D

 

import com.atlassian.jira.component.ComponentAccessor

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

return user

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events